Hey, am new to nixtlaverse and am very confused wi...
# neural-forecast
d
Hey, am new to nixtlaverse and am very confused with the models behavior 😉 I have something like this:
models = [
LSTM(h=horizon,
max_steps=max_steps,
context_size=lookback,
scaler_type='robust',
hist_exog_list=['a', 'b'],
futr_exog_list=['c'],
encoder_hidden_size=32,
decoder_hidden_size=32
)
]
nf.fit(df=Y_df)
nf.predict() # NOT working
nf.predict(futr_df=futr_df)  # working but not using hist features ??! 0_O
nf.predict(df=hist_df,futr_df=futr_df)  # NOT working
nf.predict(hist_df)  # NOT working
what am i missunderstanding / doing wrong?
m
Hello! What's the error when your run
predict
?
d
ValueError: Models require the following future exogenous features: {'c'}. Please provide them through the
futr_df
argument.
m
Awesome! So that means that you need to provide a dataframe containing the future values of your exogenous features. That way, the model can use them to make predictions. You can look at this tutorial for a detailed guide. I hope this helps!
d
but i did its not working except
nf.predict(futr_df=futr_df)
but then its using only future features to predict...
the tutorial u link uses only futr features to predict as well despite the model has
hist_exog_list
i need model taht predicts upon hist variables mostly; the futr is just to explain 1% extra
here is fully self contained code to replicate:
Copy code
import pandas as pd
import numpy as np

# bogus DATA
start_date = '2023-01-01'
end_date = '2023-01-07'

timestamps = pd.date_range(start=start_date, end=end_date, freq='H')

data = {
    'ds': timestamps,
    'a': np.random.rand(len(timestamps)),
    'b': np.random.rand(len(timestamps)),
    'c': np.random.rand(len(timestamps)),
    'y': np.random.rand(len(timestamps)),
    'unique_id': ['A'] * len(timestamps)
}

df = pd.DataFrame(data)

split_index = int(len(df) * 0.8)

train_df = df.iloc[:split_index]
test_df = df.iloc[split_index:]

futr_df = test_df[['c','ds','unique_id']].reset_index()
from neuralforecast import NeuralForecast
from neuralforecast.models import LSTM

horizon = 1
lookback=10
max_steps=1

models = [
    LSTM(h=horizon,
        max_steps=max_steps,
        context_size=lookback,
        scaler_type='robust',
        hist_exog_list=['a', 'b'],
        futr_exog_list=['c'],
        encoder_hidden_size=32,
        decoder_hidden_size=32
        )
]

nf = NeuralForecast(models=models, freq='H')
nf.fit(df=train_df)
nf.predict(futr_df=futr_df)  # working but i want hist dependent pred too
nf.predict()  # NOT working
m
With
hist_exog_list
, the model uses that information to train and make predictions already. What you can do is also forecast your data in
hist_exog_list
and pass it in the
futr_df
.
d
can you please add a line of code to do the predictions based on hist_? I am not sure i get what you mean, do u mean this ``nf.predict(futr_df=test_df`` it works in the above example. So this uses the variables listed both in hist_exog_list + the vars in futr_exog... to predict?
m
Yes!
d
thx, Sir
ehm i got ahead of myself it always only predict T_lastTrain+horizon how do i predict arbitrary time in the future?
this is the way for an arbitrary time point?
nf.predict(df=test_df[:arb_time_Point] , futr_df=futr_df[:arb_time_Point+horizon])
m
You could simply forecast over the entire horizon and then select the predictions starting at any point inside. Neuralforecast supports only forecasting the a length of horizon or less.
d
ok thx