-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
62 lines (49 loc) · 1.9 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import pandas as pd
import numpy as np
import warnings
warnings.filterwarnings('ignore')
global ship1
global ship2
def LoadData(path, kind):
global ship1
global ship2
if kind == 1:
ship1 = pd.read_csv(path)
ship1 = ship1.set_index('timestamp')
else:
ship2 = pd.read_csv(path)
ship2 = ship2.set_index('timestamp')
def new_data(data1, data2):
frame = [data1, data2]
new_data = pd.concat(frame, sort=False, ignore_index=True)
from sklearn.utils import shuffle
new_data = shuffle(new_data)
return new_data
# def column_selection(data):
# X = data[['engine_power', 'Rot', 'Rotation', 'RudderAngle', 'SPEED_KNOTS', 'WindDiration', 'WindSpeed', 'draft',
# 'reWind', 'trim']]
# Y = data['ship_FuelEfficiency']
# from sklearn.ensemble import RandomForestRegressor
# model = RandomForestRegressor(n_estimators=100, oob_score=True, n_jobs=-1, random_state=50,
# max_features="auto", min_samples_leaf=100)
# model.fit(X, Y)
# importances = model.feature_importances_
# indices = np.argsort(importances)[::-1]
# feat_labels = X.columns
# a = []
# for f in range(X.shape[1]):
# temp = feat_labels[indices[f]]
# a.append(temp)
# select_columns = ['draft', 'engine_power', 'SPEED_KNOTS', 'Rotation', 'WindSpeed']
# return select_columns
path = '/Users/sunquanhan/Desktop/GUI_Demo/ship1_total.csv'
LoadData(path, 1)
LoadData(path, 2)
data = new_data(ship1, ship2)
X = data[['engine_power', 'Rot', 'Rotation', 'RudderAngle', 'SPEED_KNOTS', 'WindDiration', 'WindSpeed', 'draft',
'reWind', 'trim']]
Y = data['ship_FuelEfficiency']
from sklearn.ensemble import RandomForestRegressor
model = RandomForestRegressor(n_estimators=100, oob_score=True, n_jobs=-1, random_state=50,
max_features="auto", min_samples_leaf=100)
model.fit(X,Y)