predict-coin/train_gift.py

42 lines
1008 B
Python

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()
units = 400
model.add(LSTM(units, activation='relu', input_shape=(4,1) ))
model.add(Dropout(0.2))
model.add(Dense(1))
model.summary()
model.compile(loss='mse', optimizer='adam')
model.fit(x_train, y_train, batch_size=1, epochs=50)
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])
if abs(comp) >= 0.1:
print("测结果:", p_data[i][0], "测:", tx_train[i], "真实:", ty_train[i])