forked from hunkim/DeepLearningZeroToAll
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathklab-07-3-linear_regression_min_max.py
41 lines (31 loc) · 1.27 KB
/
klab-07-3-linear_regression_min_max.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
from keras.models import Sequential
from keras.layers import Dense, Activation
from sklearn.preprocessing import MinMaxScaler
import numpy as np
np.random.seed(777) # for reproducibility
xy = np.array([[828.659973, 833.450012, 908100, 828.349976, 831.659973],
[823.02002, 828.070007, 1828100, 821.655029, 828.070007],
[819.929993, 824.400024, 1438100, 818.97998, 824.159973],
[816, 820.958984, 1008100, 815.48999, 819.23999],
[819.359985, 823, 1188100, 818.469971, 818.97998],
[819, 823, 1198100, 816, 820.450012],
[811.700012, 815.25, 1098100, 809.780029, 813.669983],
[809.51001, 816.659973, 1398100, 804.539978, 809.559998]])
# very important. It does not work without it.
scaler = MinMaxScaler(feature_range=(0, 1))
xy = scaler.fit_transform(xy)
print(xy)
x_data = xy[:, 0:-1]
y_data = xy[:, [-1]]
model = Sequential()
model.add(Dense(1, input_dim=4))
model.add(Activation('linear'))
model.summary()
model.compile(loss='mse',
optimizer='sgd',
metrics=['accuracy'])
history = model.fit(x_data, y_data, epochs=100)
predictions = model.predict(x_data)
score = model.evaluate(x_data, y_data)
print('Prediction: \n', predictions)
print('Cost: ', score[0])