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

Matej

08/13/2023, 2:37 PM
One more question : ), I am trying to follow the MSTL tutorial: https://nixtla.github.io/statsforecast/docs/tutorials/multipleseasonalities.html This section throws an exception for me and I am unable to get around it:
Copy code
models = [MSTL(
    season_length=[24, 24 * 7], # seasonalities of the time series 
    trend_forecaster=AutoARIMA() # model used to forecast trend
)]

forecasts = sf.predict(h=24, level=[90])
forecasts.head()
I get the following exception when I include the level parameter in the predict method:
Copy code
Exception: You have to instantiate either the trend forecaster class or MSTL class with `prediction_intervals` to calculate them
(Without the level=[90] parameter everything seem to work fine) I have also tried adding the conformal intervals:
Copy code
MSTL(
        season_length=[24, 24*7],
        trend_forecaster=AutoARIMA(),
        prediction_intervals=ConformalIntervals(
            h = 3, # fcst horizon
            n_windows = 10 # number of CV windows, (conformal scores)
            )
    )
This also causes the predict method to crash with the following error:
Copy code
ValueError: operands could not be broadcast together with shapes (1,24) (10,3)
I have statsforecasts 1.5.0 btw. Thanks in advance for patience.
pyproject.toml
k

Kevin Kho

08/13/2023, 11:24 PM
So with the Conformal Interval,
h
needs to equal the
predict
. So try
h=24
, and then they can be broadcasted
I can replicate on 1.5.0. I think that syntax will be changed with the new released. It’s already in master. You can do:
Copy code
from statsforecast.utils import ConformalIntervals

# Create a list of models and instantiation parameters 
intervals = ConformalIntervals(h=24, n_windows=2)

mstl = MSTL(
    season_length=[24, 24 * 7], # seasonalities of the time series 
    trend_forecaster=AutoARIMA(prediction_intervals=intervals) # model used to forecast trend,
)
sf = StatsForecast(
    models=[mstl], # model used to fit each time series 
    freq='H', # frequency of the data
)
sf = sf.fit(df=df)
forecasts = sf.predict(h=24, level=[90])
forecasts.head()
The
prediction_intervals
on the
MSTL
class doesn’t work quite yet. You need to use it on the models (again, on the master branch)
m

Matej

08/14/2023, 9:15 AM
Thanks so much for such a quick reply
MSTL does not have its own conf. intervals. ?
k

Kevin Kho

08/14/2023, 4:55 PM
no it goes to the Trend forecaster
6 Views