Search code examples
pythonparametersmodel

How to get model specification/paramters for models estimated with Nixtla's statsforecast package


I am using the statsforecast package to fit an AUTOarima model with an external regressor, which works fine. I need to get the model parameters and modify the parameter for the external regressor and rerun the model for scenario analysis. I also need a model summary to provide with my research. How can I get the model specification/parameters and/or a summary from the fitted model in the statsforecast package?

A similar questions has been asked on Github (https://github.com/Nixtla/statsforecast/issues/72) but remains unanswerd as of now.

I looked through the documentation (https://nixtla.github.io/statsforecast/models.html) but I couldn't locate any method similar to model.get_params() or model.summary() from the sklearn package or any method that would allow me to print the model parameters or a model summary.


Solution

  • Nixtla statsforecast model stores those information under the hood. There is no method like get_params() to access those, but you can do that pretty easily when you have the model trained. Please see the example below:

    import pandas as pd
    from statsforecast import StatsForecast
    from statsforecast.models import AutoARIMA, AutoCES, AutoETS, AutoTheta
    
    train_dt = pd.read_csv('//data_you_will_forecast_in_stastforecast_format.csv')
    
    models = [
            AutoARIMA(season_length=period),
            AutoTheta(season_length=period),
            AutoETS(season_length=period),
            AutoCES(season_length=period),
        ]
    
    sf = StatsForecast(df=train_df,  # used data frame
                       models=models, # a list of models. Select the models you want                                                                      from models and import them.
                       freq='MS',  # a string indicating the frequency of the data.
                       n_jobs=-1,
                       fallback_model=SeasonalNaive(season_length=period)  # a model to be used if a model fails.
    
    sf.fit(train_df)
    

    When sf models are fit, the data are accessible as follows:

    sf.fitted_ # access an array of fitted models.
    sf.fitted_[0][n].model_ # access dictionary of all model's parameters
    

    The dictionary will give all information on the fitted model, including in-sample data, aic (or other metric by which the best model was selected), best model parameters, and many others. In case of AutoARIMA it is under the key 'arma'