predict-coin/train_gift.py

42 lines
1.0 KiB
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__":
2021-03-25 09:36:09 +00:00
x_train, y_train, tx_train, ty_train, input_shape = load_gift_data()
2021-03-19 09:14:35 +00:00
model = Sequential()
2021-03-23 10:12:32 +00:00
units = 400
2021-03-19 09:14:35 +00:00
2021-03-25 09:36:09 +00:00
model.add(LSTM(units, activation='relu', input_shape=input_shape ))
2021-03-23 10:12:32 +00:00
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-25 09:36:09 +00:00
model.fit(x_train, y_train, batch_size=128, epochs=1500)
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])