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, input_shape = load_gift_data() model = Sequential() units = 400 model.add(LSTM(units, activation='relu', input_shape=input_shape )) 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=128, epochs=1500) 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])