我正在努力实现的目标。
我试图根据下表的多个输入参数预测天然气的开盘价(“NG Open”)。我遵循了一些教程,但它们没有解释特定格式背后的原因。经过多次试验和错误,代码正在工作,但需要对重新塑造数据有一些了解。
数据集 - 只有几行。
Contract NGLast NGOpen NGHigh NGLow NGVolumes COOpen COHigh COLow
2018-12-01 4.487 4.50 4.60 4.03 100,000 56.00 58.00 50.00
2019-01-01 4.450 4.52 4.61 4.11 93000 51.00 53.00 45.00
代码
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from keras.layers import Dense
from keras.models import Sequential
from keras.layers import LSTM
import date time
from keras import metrics
from sklearn.preprocessing import MinMaxScaler
data = pd.read_excel("C:\Futures\Futures.xls")
data['Contract'] = pd.to_datetime(data['Contract'],unit='s').dt.date
data['NG Last'] = data['NG Last'].str.rstrip('s')
data['CO Last'] = data['CO Last'].str.rstrip('s')
COHigh = np.array([data.iloc[:,8]])
COLow = np.array([data.iloc[:,9]])
NGLast = np.array([data.iloc[:,1]])
NGOpen = np.array([data.iloc[:,2]])
NGHigh = np.array([data.iloc[:,3]])
X = np.concatenate([COHigh,COLow, NGLast,NGOpen], axis =0)
X = np.transpose(X)
Y = NGHigh
Y = np.transpose(Y)
scaler = MinMaxScaler()
scaler.fit(X)
X = scaler.transform(X)
scaler.fit(Y)
Y = scaler.transform(Y)
**X = np.reshape(X,(X.shape[0],1,X.shape[1]))**
print(X.shape)
model = Sequential()
**model.add(LSTM(100,activation='tanh',input_shape=(1,4),** recurrent_activation='hard_sigmoid'))
model.add(Dense(1))
model.compile(loss='mean_squared_error', optimizer='rmsprop', metrics = [metrics.mae])
model.fit(X,Y,epochs = 10,batch_size=1,verbose=2)
Predict = model.predict(X,verbose=1)
题
上面用星号标记的代码背后的原因是什么?
1> 我有四列作为输入所以不应该是X = np.reshape(X,(X.shape[0],1,X.shape[1], X.Shape[2],X.shape[ 3])) ? 等等所有被视为输入的列?
2> 我需要解释下面这一行中的参数。model.add(LSTM(100,activation='tanh',input_shape=(1,4), recurrent_activation='hard_sigmoid'))
大话西游666
相关分类