Hey, I am running through your stastsforecast docu...
# general
a
Hey, I am running through your stastsforecast documentation and struggling to understand if there is an option to save the models? Do I just pickle it? Example utilisation of the package:
Copy code
df = process_df()

    models = [
            AutoARIMA(max_D=12, season_length=12),
    ]

    sf = StatsForecast(
            df=df,
            sort_df=True,
            models=models,
            freq='M',
            n_jobs=-1,
    )
s
had this problem too. ended up hacking in a solution:
Copy code
fitted_models = sf.fit().fitted_
You can then pickle these fitted models. Note there may be more than one model. When you want to load them again:
Copy code
new_sf = StatsForecast(df=df, models=placeholder_models)  # the models you put in here are irrelevant
sf.fitted_ = fitted_models
sf.predict(horizon)
@Nixtla Team maybe I should have put up a PR for this, apologies for laziness on my end!
a
Hey Sam, thanks for the response, from what I gathered
.fit
is callable of
StatsForecast
class. That assumption is based on the fact that when calling
.forecast
method it autofits the models. First question: Would it be better to call
.fit
after initiating the class with all the params? Second question: would
fit
create ?incapsulated list? with all the fitted models? hence this code:
Copy code
[model.fitted_ for model in sf.fit()]
s
1. Indeed forecast() fits the models. Only call .fit() then .predict() imo if you want to split these steps for some other reason. 2. Ye it does create a list of fitted models.
a
okay, so utilising
fit
and
predict
in the case of manual fitting. Would be great to have a PR about creating a
save
method.
k
Yeah I chatted with them about it. The reason is that the overhead can be a bit big. If you have 1000 timeseries, the weights for each timeseries would be saved so it’s more common to just call the forecast straight. The PR makes sense though
a
@Sam Miller I dabbled a bit around with fitted models and it is a bit confusing on what's happening under the hood, when looking at
sf.fit().fitted_
I can see replicas of the a single model that was issues, are they same model but fitted with different params? AutoARIMA example:
Copy code
[array([AutoARIMA], dtype=object), array([AutoARIMA], dtype=object), array([AutoARIMA], dtype=object), array([AutoARIMA], dtype=object), array([AutoARIMA], dtype=objec
t), array([AutoARIMA], dtype=object), array([AutoARIMA], dtype=object), array([AutoARIMA], dtype=object), array([AutoARIMA], dtype=object), array([AutoARIMA], dtype=ob
ject), array([AutoARIMA], dtype=object), array([AutoARIMA], dtype=object)]
@Kevin Kho I just attempted a test run with 400 data rows (not much, just a test) and 10 above ARIMA models, the size of the pickle is 3.9kb
s
there may be a separate model for each unique_id in your data
a
🤦‍♂️omg that makes 100% sense hahaha
s
dw it confused me too when i first saw it
a
is there a way to associate the model with its unique id? incremental increase according to alphabetical order?
s
i haven't figured that one out yet, but you can probably hack it
👍 1
k
Yes the best model for each fitted model for each unique id in your data. So if you try ETS and AutoARIMA, you will see double the models. The unique_id should resolve when you call predict so you shouldn’t need to handle it yourself?
m
check out this thread @Piotr Pomorski. I think it answers what you were asking.
p
@Martin Bel this is for statsforecast, I'm using mlforecast, which does not have .fitted_ attribute, unfortunately
👍 1