You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
from tensorflow.keras.layers import LSTM
出现问题的代码块:
def fit_lstm(train, n_lag, n_seq, n_batch, nb_epoch, n_neurons):
# (train, 历史1lag, 预测3个步长, 用1 batch数据, 15网络次数_权重更新, 1个神经元)
# 重塑训练数据格式 [samples, timesteps, features]
X, y = train[:, 0:n_lag], train[:, n_lag:] # 1列22个历史数据,3列22个未来数据
X = X.reshape(X.shape[0], 1, X.shape[1]) # (22,1,1)
# 配置一个LSTM神经网络,添加网络参数
model = Sequential()
#1 model.add(LSTM(n_neurons,input_length=X.shape[1], input_dim=X.shape[2])) #TEST: input_length
#1 return Unrecognized keyword arguments passed to LSTM: {'input_length': 1}
#2 model.add(LSTM(units=n_neurons,batch_size=n_batch,input_shape=(X.shape[1], X.shape[2]))) #TEST: batch_size
#2 return Unrecognized keyword arguments passed to LSTM: {'batch_size': 1}
#3 model.add(LSTM(units=n_neurons,activation='tanh',batch_input_shape=(None, X.shape[1], X.shape[2]),stateful=True)) #TEST: batch_input_shape
#3 return Unrecognized keyword arguments passed to LSTM: {'batch_input_shape': (1, 1, 1)}
model.add(LSTM(units=n_neurons,input_shape=(X.shape[1], X.shape[2])))
# return 'Sequential' object has no attribute 'reset_states'
# stateful = True --> 需要shuffle = False
model.add(Dense(y.shape[1]))
model.compile(loss='mean_squared_error', optimizer='adam')
# 调用网络,迭代数据对神经网络进行训练,最后输出训练好的网络模型
for i in range(nb_epoch):
model.fit(X, y, epochs=1, batch_size=n_batch, verbose=0, shuffle=False)
model.reset_states()
return model
model = fit_lstm(train, n_lag, n_seq, n_batch, n_epochs, n_neurons)
尝试各种不同的add lstm的方法,均失败
安装包版本:
tensorflow 2.16.1
keras 3.2.1
python 3.9.19
The text was updated successfully, but these errors were encountered:
yawn1996
changed the title
多步预测的LSTM网络--Unrecognized keyword arguments passed to LSTM: {'batch_size': {1,1,1}}
多步预测的LSTM网络.py--Unrecognized keyword arguments passed to LSTM: {'batch_size': {1,1,1}}
May 24, 2024
代码修改如下:
出现问题的代码块:
尝试各种不同的add lstm的方法,均失败
安装包版本:
tensorflow 2.16.1
keras 3.2.1
python 3.9.19
The text was updated successfully, but these errors were encountered: