用 LSTM 预测未来值?

问题描述 投票:0回答:0
# generate the input and output sequences
n_lookback = 20  # length of input sequences (lookback period)
n_forecast = 20  # length of output sequences (forecast period)

# generate the forecasts
X_ = df[- n_lookback:]  # last available input sequence
X_ = X_.reshape(1, n_lookback, 1)

Y_ = model.predict(X_).reshape(-1, 1)
Y_ = scaler.inverse_transform(Y_)

# organize the results in a data frame
df_past = dataset
df_past.rename(columns={'Harga': 'Actual'}, inplace=True)
df_past['Forecast'] = np.nan
df_past['Forecast'].iloc[-1] = df_past['Actual'].iloc[-1]

df_future = pd.DataFrame(columns=['Tanggal', 'Actual', 'Forecast'])
df_future['Tanggal'] = pd.date_range(start=df_past['Tanggal'].iloc[-1] + pd.Timedelta(days=1), periods=n_forecast)
df_future['Forecast'] = Y_.flatten()
df_future['Actual'] = np.nan

results = df_past.append(df_future).set_index('Tanggal')

这是完整代码 https://pastebin.com/VZ5u5dLp 当我尝试运行它时,我只能生成 n+1 预测*,* 但我无法获得 n 步预测。例如*,*即使我使用 20 天的值作为预测基准,我也只能预测未来 1 天的情况。当我尝试将 n_forecast 修改为 1 以外的数字时,它会生成 ValueError。有人可以帮助我吗?预先感谢。

python lstm
© www.soinside.com 2019 - 2024. All rights reserved.