-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtrain.py
More file actions
39 lines (33 loc) · 1.06 KB
/
train.py
File metadata and controls
39 lines (33 loc) · 1.06 KB
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
import matplotlib; matplotlib.rcParams["savefig.directory"] = "."
import numpy as np
import pylab as plt
import sklearn as skl
from sklearn.model_selection import train_test_split
from sklearn.neural_network import MLPRegressor
import joblib
X = np.load("X.npy")
Y = np.load("Y.npy")
scaler = skl.preprocessing.StandardScaler()
yscaler = skl.preprocessing.StandardScaler()
x_train, x_test, y_train, y_test = train_test_split(X, Y, test_size=0.20, random_state=1)
scaler.fit(x_train)
y_train = yscaler.fit_transform(y_train)
y_test = yscaler.transform(y_test)
x_train_scaled = scaler.transform(x_train)
x_test_scaled = scaler.transform(x_test)
mlpr = MLPRegressor(
hidden_layer_sizes=(1000,1000,800,700,600,500),
activation='relu',
solver='adam',
learning_rate_init=4e-4,
max_iter=160,
tol=2.5e-5,
random_state=1,
verbose=True
)
mlpr.fit(x_train_scaled, y_train)
y_pred = mlpr.predict(x_test_scaled)
ts = mlpr.score(x_train_scaled, y_train)
vs = mlpr.score(x_test_scaled, y_test)
print(ts, vs)
joblib.dump((scaler, yscaler, mlpr), "sklearn_model.pkl")