predict-coin/train_gift.py

42 lines
1008 B
Python
Raw Normal View History

2021-03-19 09:14:35 +00:00
from keras.models import Sequential
from keras.layers import Dense, Dropout, Embedding
from keras.layers import InputLayer, Activation
from keras.layers import LSTM
from keras import backend
import pymysql
import pickle
import os
import numpy
from data import load_gift_data
if __name__ == "__main__":
x_train, y_train, tx_train, ty_train = load_gift_data()
model = Sequential()
2021-03-23 10:12:32 +00:00
units = 400
2021-03-19 09:14:35 +00:00
2021-03-23 10:12:32 +00:00
model.add(LSTM(units, activation='relu', input_shape=(4,1) ))
model.add(Dropout(0.2))
2021-03-19 09:14:35 +00:00
model.add(Dense(1))
model.summary()
model.compile(loss='mse', optimizer='adam')
2021-03-23 10:12:32 +00:00
model.fit(x_train, y_train, batch_size=1, epochs=50)
2021-03-19 09:14:35 +00:00
model.save("./predict_gift")
p_data = model.predict(tx_train)
for i in range(len(p_data)):
comp = (p_data[i][0] - ty_train[i]) / ty_train[i]
print(comp, p_data[i][0], ty_train[i])
2021-03-23 10:12:32 +00:00
if abs(comp) >= 0.1:
2021-03-19 09:14:35 +00:00
print("测结果:", p_data[i][0], "测:", tx_train[i], "真实:", ty_train[i])