Search code examples
pythonsktime

Feature importance or model summary in sktime


I'm going through the documentation of the sktime package. One thing I just cannot find is the feature importance (that we'd get with sklearn models) or model summary (like the one we can obtain from statsmodels). Is it something that is just not implemented yet?

It seems that this functionality is implemented for models like AutoETS or AutoARIMA.

from matplotlib import pyplot as plt

from sktime.datasets import load_airline
from sktime.forecasting.model_selection import temporal_train_test_split
from sktime.forecasting.base import ForecastingHorizon
y = load_airline()
y_train,y_test = temporal_train_test_split(y)
fh = ForecastingHorizon(y_test.index, is_relative=False)

from sktime.forecasting.ets import AutoETS
model = AutoETS(trend='add',seasonal='mul',sp=12)
model.fit(y_train,fh=y_test.index)
model.summary()

I wonder if these summaries are accessible from instances like ForecastingPipeline.


Solution

  • Ok, I was able to solve it myself. I'm really glad the functionality is there!

    The source code for ForecastingPipeline indicates that an instance of this class has an attribute steps_ - it holds the fitted instance of the model in a pipeline.

    from sktime.forecasting.compose import ForecastingPipeline
    
    model = ForecastingPipeline(steps=[
    ("forecaster", AutoETS(sp=1))])
    model.fit(y_train)
    
    model.steps_[-1][1].summary() # model.steps[-1][1].summary() would throw an error
    

    The output of model.steps_ is [('forecaster', AutoETS())] (as mentioned before AutoETS() is in this case already fitted).