import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from pylab import rcParams
rcParams['figure.figsize'] = 12, 4

import sklearn
import mysterious_ship as ms
t = np.arange(0,1000,1)
df_wind = ms.wind(t=t, u_mean=10, gust_mean=0.1,  gust_std=0.5, t_mean=300, t_std=100, components=10)
df_wind.head()
0 1 2 3 4 5 6 7 8 9 u
0 0.021414 -0.049992 0.333796 0.769636 0.099905 0.070593 0.458019 -0.255920 0.187504 0.206486 11.841441
1 0.015030 -0.050760 0.333623 0.771459 0.097886 0.072645 0.437070 -0.250202 0.191139 0.213881 11.831772
2 0.008638 -0.051496 0.333325 0.770705 0.095630 0.074648 0.415684 -0.244394 0.194603 0.220941 11.818282
3 0.002240 -0.052201 0.332902 0.767374 0.093141 0.076601 0.393882 -0.238499 0.197891 0.227655 11.800986
4 -0.004160 -0.052874 0.332353 0.761480 0.090426 0.078503 0.371686 -0.232517 0.201000 0.234013 11.779911
fig,ax=plt.subplots()
df_wind.plot(ax=ax)
<AxesSubplot:>
data = ms.ShipData(t_max=500)
data.data_real.head()
u P T u_w fx_wind
0.0 7.000000 7000.000000 1000 10.026627 -1.005333
0.1 6.999068 6999.068418 1000 10.027253 -1.005458
0.2 6.998137 6998.137316 1000 10.027870 -1.005582
0.3 6.997207 6997.206510 1000 10.028476 -1.005703
0.4 6.996276 6996.276250 1000 10.029074 -1.005823
for key in ['u','P']:
    fig,ax=plt.subplots()
    data.data_measure.plot(y=key, label='measured', ax=ax);
    data.data_real.plot(y=key, label='true', ax=ax);
    ax.set_ylabel(key)
from sklearn.model_selection import train_test_split
X = data.data_measure.copy()
y = X.pop('P')

test_size=0.33
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=test_size, random_state=42)

#train_index = int((1-test_size)*len(X))
#X_train = X.iloc[0:train_index]
#y_train = X.iloc[0:train_index]
#X_test = X.iloc[train_index:]
#y_test = X.iloc[train_index:]
#
for X_ in [X_train,X_test]:
    pass
    #X_['u_w**2'] = X_['u_w']**2
    #X_['u**2'] = X_['u']**2
    
from sklearn.tree import DecisionTreeRegressor

model = DecisionTreeRegressor()
model.fit(X_train, y_train)
DecisionTreeRegressor()
model.score(X_test, y_test)
0.9700538141331929