https://github.com/nixtla logo
#general
Title
# general
t

Tia Guo

11/03/2022, 7:49 PM
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

fede (nixtla) (they/them)

11/03/2022, 7:55 PM
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

Tia Guo

11/03/2022, 7:56 PM
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

fede (nixtla) (they/them)

11/03/2022, 7:57 PM
yes, that’s correct, currently we don’t have levels implemented for ETS but we are working on including them
❤️ 1
t

Tia Guo

11/03/2022, 7:59 PM
hmm I tested the code you shared above and it's still giving me the error like this..
f

fede (nixtla) (they/them)

11/03/2022, 8:00 PM
ahh ok, are you also passing
level
to
forecast
right?
t

Tia Guo

11/03/2022, 8:00 PM
yeah...is this the root cause of the error?
f

fede (nixtla) (they/them)

11/03/2022, 8:03 PM
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

Tia Guo

11/03/2022, 8:03 PM
hmmm I removed the level argument but the error persists...
f

fede (nixtla) (they/them)

11/03/2022, 8:06 PM
oh that’s unexpected, may I see your code?
t

Tia Guo

11/03/2022, 8:10 PM
wow I run the code again and it worked thru this time!! thanks for the help!
f

fede (nixtla) (they/them)

11/03/2022, 8:10 PM
nice! i will fix the levels error and i’ll let you know once it is resolved
t

Tia Guo

11/03/2022, 8:12 PM
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

fede (nixtla) (they/them)

11/04/2022, 5:46 PM
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

Tia Guo

11/04/2022, 6:03 PM
This is an awesome function!! Thank you for sharing Fede!
❤️ 1
2 Views