predict-coin/train_pay.py

43 lines
1.1 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
from keras.layers import LSTM
from keras import backend
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
if __name__ == "__main__":
2021-03-26 09:14:06 +00:00
region = "Region_Arab"
x_train, y_train, tx_train, ty_train, input_shape = load_pay_data(80, region)
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-03-25 09:36:09 +00:00
model.compile(loss = 'mse', optimizer = 'adam')
2021-03-19 09:14:35 +00:00
2021-03-25 09:36:09 +00:00
model.fit(x_train, y_train, batch_size=96, epochs=1200)
2021-03-26 09:14:06 +00:00
model.save("./predict_pay_" + region)
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])