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

Akmal Soliev

02/22/2023, 3:11 PM
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

Sam Miller

02/22/2023, 3:56 PM
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

Akmal Soliev

02/22/2023, 4:04 PM
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

Sam Miller

02/22/2023, 4:06 PM
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

Akmal Soliev

02/22/2023, 4:08 PM
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

Kevin Kho

02/22/2023, 7:25 PM
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

Akmal Soliev

02/23/2023, 3:26 PM
@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

Sam Miller

02/23/2023, 4:32 PM
there may be a separate model for each unique_id in your data
a

Akmal Soliev

02/23/2023, 4:50 PM
🤦‍♂️omg that makes 100% sense hahaha
s

Sam Miller

02/23/2023, 4:50 PM
dw it confused me too when i first saw it
a

Akmal Soliev

02/23/2023, 4:51 PM
is there a way to associate the model with its unique id? incremental increase according to alphabetical order?
s

Sam Miller

02/23/2023, 5:00 PM
i haven't figured that one out yet, but you can probably hack it
👍 1
k

Kevin Kho

02/23/2023, 5:50 PM
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

Martin Bel

03/13/2023, 5:20 PM
check out this thread @Piotr Pomorski. I think it answers what you were asking.
p

Piotr Pomorski

03/14/2023, 12:35 PM
@Martin Bel this is for statsforecast, I'm using mlforecast, which does not have .fitted_ attribute, unfortunately
👍 1
3 Views