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
I am working on a time series forecasting project and facing a challenge with multistep forecasting.
Currently, I have a model trained to predict one step ahead, but I need to adapt this approach to predict multiple steps ahead more efficiently. I need to keep training with h=1.
@contextmanagerdefsuppress_output():
withopen(os.devnull, 'w') asfnull:
old_stdout=sys.stdoutold_stderr=sys.stderrsys.stdout=fnullsys.stderr=fnulltry:
yieldfinally:
sys.stdout=old_stdoutsys.stderr=old_stderrlogging.getLogger("pytorch_lightning").setLevel(logging.ERROR)
defpredict_multistep(nf, dataset, n_steps, mode='OSA'):
"""#+ This function performs multi-step forecasting using a trained NeuralForecast model.#+ Parameters:#+ nf (NeuralForecast): The trained NeuralForecast model.#+ dataset (pandas.DataFrame): The dataset containing the time series data.#+ n_steps (int): The number of steps to forecast.#+ mode (str): The forecasting mode. It can be either 'OSA' (One Step Ahead) or 'FR' (Free Simulation).#+ Returns:#+ pandas.DataFrame: A DataFrame containing the forecasted values and actual values.#+ """data=dataset.copy()
id=data['unique_id'].values[0]
predictions= []
# One Step Ahead prediction#+ifmode=='OSA':
foriinrange(n_steps):
withsuppress_output():
y_hat=nf.predict(test_data.iloc[i:win+i,:])
row= {'unique_id': id,
'ds':y_hat['ds'].values[0],
'y':dataset.iloc[win+i,:]['y'],
'y_hat':y_hat['LSTM'].values[0]}
predictions.append(row)
# Free Simulation prediction#+elifmode=='FR':
ini=data.index[0]
foriinrange(n_steps):
withsuppress_output():
y_hat=nf.predict(data.iloc[i:win+i,:])
data.loc[ini+i+win,'y'] =y_hat['LSTM'].values[0]
row= {'unique_id': id,
'ds':y_hat['ds'].values[0],
'y':dataset.iloc[win+i,:]['y'],
'y_hat':y_hat['LSTM'].values[0]}
predictions.append(row)
else:
raiseValueError("Invalid mode. Choose between 'one_step_ahead' and 'free_simulation'.")
returnpd.DataFrame(predictions)
This approach is considerably slow. Is there any other model to make this prediction?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi,
I am working on a time series forecasting project and facing a challenge with multistep forecasting.
Currently, I have a model trained to predict one step ahead, but I need to adapt this approach to predict multiple steps ahead more efficiently. I need to keep training with h=1.
This approach is considerably slow. Is there any other model to make this prediction?
Beta Was this translation helpful? Give feedback.
All reactions