Mysterious ship data
Develop a machine learning ship performance model to predict ship power.
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()
fig,ax=plt.subplots()
df_wind.plot(ax=ax)
data = ms.ShipData(t_max=500)
data.data_real.head()
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)
model.score(X_test, y_test)