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

Gerard Conangla Planes

06/29/2023, 2:40 PM
Hello Nixtla team, I have a question regarding statsforecast models: how can I save them to reuse them between sessions? I can't seem to find a "save" or "load" method, for the ARIMA method for example, in the documentation. If there is nothing out of the box, what do you recommend? Something like joblib?
a

Akmal Soliev

06/29/2023, 2:59 PM
Literally worked on that today 😄 So, at current moment, this is what I came to:
Copy code
from statsforecast import StatsForecast
from statsforecast.models import (
    AutoARIMA,
)
# Create a list of models and instantiation parameters
models = [
    AutoARIMA(season_length=24),
]
# Instantiate StatsForecast class as sf
sf = StatsForecast(
    df=Y_df, 
    models=models,
    freq='H', 
    n_jobs=-1,
    verbose=True
)
sf.fit()
fitted_model = sf.fitted_
# save the models with pickle
step 2 loading:
Copy code
empty_models = []
sf2 = StatsForecast(
    df=Y_df, 
    models=test_models,
    freq='H', 
    n_jobs=-1,
    verbose=True
)
sf2.models = fitted_model
fitted_model
is multi-dim array that you can use to index it based on the prefered model and its iterations
d

Deepanjan Datta

09/24/2023, 4:58 PM
Hi @Akmal Soliev, I am trying to load an already trained MLForecast model for reuse. Is there anyway out for this ? will this "fitted_" method work for MLForecast as well ?
n

Nasreddine D

10/02/2023, 9:11 PM
Hi @Akmal Soliev, Can you clarify your code please? In step one, do you do something with the "fitted_model"? Do you save it as a pickle? Could you please complete your code if there something missing? In step 2, you put "test_models", where does it come from? I am trying, to save a model in a MLOps pipeline, but I can't figure how to do it. Last question, does it work to save a model that we used with cross_validation? Thank you for your help and clarification.
a

Akmal Soliev

10/03/2023, 2:40 PM
Hey @Nasreddine D it is an array, hence, you can save it as a pickle if you want
In step 2, you put "test_models", where does it come from?
from the saved file, let's say pickle
Last question, does it work to save a model that we used with cross_validation?
Haven't played with that, hence, cannot answer.
👍 1
@Nasreddine D made a little bit easier function that will save and load models.