from keras.models import Sequential from keras.layers import Dense, Dropout, Embedding from keras.layers import InputLayer from keras.layers import LSTM from keras import backend as K from keras.losses import mean_squared_error from keras.layers.recurrent import SimpleRNN import pymysql import pickle import os import numpy from data import load_pay_data def mean_squared_error(y_true, y_pred): print(dir(y_true), y_true.consumers) print(y_true, y_pred) return K.mean(K.square(y_pred - y_true), axis=-1) if __name__ == "__main__": x_train, y_train, tx_train, ty_train, input_shape = load_pay_data(80) model = Sequential() units = 500 model.add(LSTM(units, activation='relu', dropout=0.1, input_shape=input_shape)) # model.add(SimpleRNN(units, activation='relu')) # model.add(Dropout(0.1)) model.add(Dense(1)) model.summary() model.compile(loss = "mse", optimizer = 'adam') model.fit(x_train, y_train, batch_size=128, epochs=500) model.save("./predict_pay") p_data = model.predict(tx_train) for i in range(len(p_data)): print((p_data[i][0] - ty_train[i]) / ty_train[i], p_data[i][0], ty_train[i]) # print("测结果:", p_data[i][0], "测:", tx_train[i], "真实:", ty_train[i])