我正在训练一个神经网络,以学习计算移动平均值。输入是5天的值,输出是5天的移动平均值。但是神经网络无法学习它。它为所有预测提供恒定值。代码如下。
X_train = []
y_train = []
n = 2000
for i in range(5, n):
X_train.append(df.iloc[i-5:i, 0])
y_train.append(df.iloc[i-1, 2])
X_train, y_train = np.array(X_train), np.array(y_train)
X_train = np.reshape(X_train, (X_train.shape[0], X_train.shape[1], 1))
regressor = Sequential()
regressor.add(LSTM(units = 50, return_sequences = True, input_shape = (X_train.shape[1], 1)))
regressor.add(Dropout(0.2))
regressor.add(LSTM(units = 50, return_sequences = True))
regressor.add(Dropout(0.2))
regressor.add(LSTM(units = 50, return_sequences = True))
regressor.add(Dropout(0.2))
regressor.add(LSTM(units = 50))
regressor.add(Dropout(0.2))
regressor.add(Dense(units = 1))
regressor.compile(optimizer = 'adam', loss = 'mean_squared_error')
regressor.fit(X_train, y_train, epochs = 250, batch_size = 32)
我想念什么?