predict-coin/train_pay.py

47 lines
1.3 KiB
Python
Raw Permalink 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
from keras.layers import LSTM
2021-04-02 09:22:46 +00:00
from keras import backend as K
from keras.losses import mean_squared_error
2021-03-25 09:36:09 +00:00
from keras.layers.recurrent import SimpleRNN
2021-03-19 09:14:35 +00:00
import pymysql
import pickle
import os
import numpy
from data import load_pay_data
2021-04-02 09:22:46 +00:00
def mean_squared_error(y_true, y_pred):
2021-04-02 10:40:15 +00:00
print(dir(y_true), y_true.consumers)
print(y_true, y_pred)
2021-04-02 09:22:46 +00:00
return K.mean(K.square(y_pred - y_true), axis=-1)
2021-03-19 09:14:35 +00:00
if __name__ == "__main__":
2021-04-02 09:22:46 +00:00
x_train, y_train, tx_train, ty_train, input_shape = load_pay_data(80)
2021-03-19 09:14:35 +00:00
model = Sequential()
2021-03-23 10:12:32 +00:00
units = 500
2021-03-25 09:36:09 +00:00
model.add(LSTM(units, activation='relu', dropout=0.1, input_shape=input_shape))
# model.add(SimpleRNN(units, activation='relu'))
# model.add(Dropout(0.1))
2021-03-19 09:14:35 +00:00
model.add(Dense(1))
model.summary()
2021-04-02 10:40:15 +00:00
model.compile(loss = "mse", optimizer = 'adam')
2021-03-19 09:14:35 +00:00
2021-04-02 10:40:15 +00:00
model.fit(x_train, y_train, batch_size=128, epochs=500)
2021-04-02 09:22:46 +00:00
model.save("./predict_pay")
2021-03-19 09:14:35 +00:00
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])