neuralforecast icon indicating copy to clipboard operation
neuralforecast copied to clipboard

A problem of using NeuralForecast.predict_insample

Open Firefighter1992 opened this issue 4 months ago • 2 comments
trafficstars

Dear sir, Here is my code, which uses LSTM for multi-step forecasting. I have set the stat_exog_list parameter. However, when I use the predict_insample method, I cannot find a way to pass my static exogenous variables. The following error occurs: Exception: {'heat_release_rate_kw'} static exogenous variables not found in input dataset. However, it seems that predict_insample does not accept static exogenous variables as an argument. How should I resolve this issue?

The following is my code: import pandas as pd import matplotlib matplotlib.use('TkAgg')

import matplotlib.pyplot as plt from neuralforecast import NeuralForecast from neuralforecast.models import LSTM from neuralforecast.losses.pytorch import DistributionLoss

file_path = r"E:\NeuralForecast\Temperature.csv"

temp = pd.read_csv(file_path) temp['ds'] = temp['ds'].astype(int)

Y_train_df = temp[temp.ds < temp['ds'].values[-12]] Y_test_df = temp[temp.ds >= temp['ds'].values[-12]].reset_index(drop=True)

tempStatic = pd.DataFrame({ 'unique_id': [25, 50, 100, 200], 'heat_release_rate_kw': [25, 50, 100, 200] })

horizon=6 nf = NeuralForecast( models=[LSTM(h=horizon, input_size=12, loss=DistributionLoss(distribution="Normal", level=[80, 90]), scaler_type='robust', encoder_n_layers=2, encoder_hidden_size=128, decoder_hidden_size=256, decoder_layers=4, max_steps=400, futr_exog_list=[], stat_exog_list=['heat_release_rate_kw'], recurrent=True, ) ], freq=1 )

#This sentence is the error source Y_hat_df_train = nf.predict_insample(step_size = horizon)

Firefighter1992 avatar Jun 21 '25 07:06 Firefighter1992