Hi, I am using statsforecast with multiple models ...
# general
t
Hi, I am using statsforecast with multiple models (Auto ARIMA, ETS, Random Walk) and I want to get insample forecast using forecast_fitted_values. But it seems that this function cannot take multiple models at the same time. Is there any best practice other than splitting 3 models into multiple 3 fit&forecasts?
f
hey @Tia Guo! With
StatsForecast
you can recover the fitted values using
fitted=True
in the
forecast
method. After that, you just have to call
forecast_fitted_values()
without parameters to obtain the insample forecasts. Here’s a complete example,
Copy code
from statsforecast import StatsForecast
from statsforecast.models import AutoARIMA, ETS, RandomWalkWithDrift
from statsforecast.utils import AirPassengersDF as Y_df

sf = StatsForecast(df=Y_df, 
                   models=[AutoARIMA(season_length=12), ETS(season_length=12), RandomWalkWithDrift()],
                   freq='M')

forecasts = sf.forecast(h=12, fitted=True)
insample = sf.forecast_fitted_values()
👍 1
The outputs are
t
Thanks for the quick response Fede! I will test the same code on my end 🙂
just a side question, for ETS, we cannot get confidence intervals like level=90, is that correct?
f
yes, that’s correct, currently we don’t have levels implemented for ETS but we are working on including them
❤️ 1
t
hmm I tested the code you shared above and it's still giving me the error like this..
f
ahh ok, are you also passing
level
to
forecast
right?
t
yeah...is this the root cause of the error?
f
yes, since some models dont have levels implemented there is an error trying to construct the dataframe of insample forecasts. But, ideally statsforecast should return the levels only for models that have them implemented
t
hmmm I removed the level argument but the error persists...
f
oh that’s unexpected, may I see your code?
t
wow I run the code again and it worked thru this time!! thanks for the help!
f
nice! i will fix the levels error and i’ll let you know once it is resolved
t
that would be awesome! please keep me posted 🙂
@fede (nixtla) (they/them) Hi Fede, a follow-up question on the thread above, if one model among the 3 (ARIMA, RWS, ETS) cannot get a model from the training data, it's it possible to pass some random value in the result dataset and continue running, instead of shutting the run down and throwing error?
I am having this question, since I want to find the best model for a lot of datasets, if one model is throwing an error, this certain dataset won't have any other models available.
f
hey @Tia Guo! StatsForecast includes an argument called
fallback_model.
The main idea behind it is that you can pass a safe model in case that a main model fails. So, StatsForecast tries to fit the main models for each time series and if something fails, it will fit a safer model, for example,
Naive().
The code would be,
Copy code
StatsForecast(models=[AutoARIMA(), ETS()], fallback_model=Naive(), extra params)
Please let us know if that works for your use case. 🙂
t
This is an awesome function!! Thank you for sharing Fede!
❤️ 1