/
currency_value_prediction.py
59 lines (41 loc) · 1.29 KB
/
currency_value_prediction.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
from keras.layers.core import Dense, Activation
from keras.layers.recurrent import LSTM
from keras.models import Sequential
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
import matplotlib.pyplot as plt
import time
import data_loader
import numpy as np
WINDOW = 10
X, Y, options = data_loader.load_data("etherium_data_pretty.json", window_size=WINDOW, remove_features=["date"],
preprocess_args={'normaliser': StandardScaler()})
x_train, x_test, y_train, y_test = train_test_split(X, Y, test_size=0.3, random_state=0)
model = Sequential()
model.add(LSTM(
input_shape=(None, 7),
units=100,
dropout=0.2,
return_sequences=True))
model.add(LSTM(
200,
dropout=0.2,
return_sequences=False))
model.add(Dense(units=1))
model.add(Activation('linear'))
start = time.time()
model.compile(loss='mse', optimizer='rmsprop')
model.fit(
x_train,
y_train,
batch_size=512,
epochs=1,
validation_split=0.05)
predictions = model.predict(X[:1000], batch_size=512)
real_values = Y.flatten()[:1000]
indexes = np.arange(0, len(real_values))
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
plt.plot(indexes, real_values, color="red")
plt.plot(indexes, predictions, color="blue")
plt.show()