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

Toni Borders

11/03/2023, 4:33 PM
Hi again, I am trying to save off the fitted model for re-use with the StatsForecast.save() and StatsForecast.load() methods but am hitting the error in the SS. Code:
Copy code
from statsforecast import StatsForecast    

def fit():
    model = StatsForecast(df=panel_df,
                         models=[AutoARIMA(), SeasonalNaive(season_length=7)],
                         freq='D',
                         n_jobs=1,
                         verbose=True)
    model.fit(panel_df)
    model.save('/Users/tmb/PycharmProjects/data-science/UFE/output_files/model')
Error:
Copy code
AttributeError: type object 'StatsForecast' has no attribute 'save'
I have the latest version of the package installed (e.g. 1.6.0)
j

José Morales

11/03/2023, 4:40 PM
Hey. This was merged recently and hasn't been released. You can install from github if you want to use those methods or you can just use pickle/cloudpickle on the object:
Copy code
import pickle

with open('your_model.pkl', 'wb') as f:
    pickle.dump(model, f)
t

Toni Borders

11/03/2023, 4:41 PM
Ahhh thanks for the speedy reply!
Does that go for StatsForecast.plot as well?
As that doesn’t do anything when I call it.
Copy code
StatsForecast.plot(panel_df, df)
j

José Morales

11/03/2023, 4:42 PM
No, that has been there for several versions, you should be able to use it. The default engine in 1.6 is matplotlib, are you using jupyter notebooks?
t

Toni Borders

11/03/2023, 4:43 PM
No I running directly from a .py script in Pycharm
I thought I read that the default plotting engine is plotly, is this incorrect? That could be the issue, I don’t have matplotlib installed
Now I have installed matplotlib but it still isn’t working.
j

José Morales

11/03/2023, 4:50 PM
In 1.6 is matplotlib. You probably need to save the figure or do something with it. I don't think it's shown from a script
t

Toni Borders

11/03/2023, 4:52 PM
ok no worries I will figure it out.
FYI, I saved the fig and can now see it, in case anyone else has the same question.
👍 2
Copy code
x = StatsForecast.plot(panel_df)
    x.savefig('testfig.png')
r

Ramon Botella Nieto

11/14/2023, 12:04 PM
Hi there, I'm very interested in these two methods (save and load), but I work on a poetry virtual environment. What would be the normative way of introducing these changes on the statsforecast already installed in my poetry environment?
j

José Morales

11/14/2023, 3:40 PM
We're going to make a release in the following weeks. In the meantime you can install from github, I'm not sure how to set it for poetry but you might be able to specify your requirements like
git+<https://github.com/Nixtla/statsforecast|https://github.com/Nixtla/statsforecast>
r

Ramon Botella Nieto

11/14/2023, 3:46 PM
Thanx!
2 Views