# statsforecast


10/05/2023, 7:36 AM
Hi Nixtla team, first off let me say this is the best timeseries library Ive ever used. I have a question that has probably been asked already, so thanks for patience. In this tutorial: This section:
Copy code
from time import time

# Get the current time before forecasting starts, this will be used to measure the execution time
init = time()

# Call the forecast method of the StatsForecast instance to predict the next 28 days (h=28) 
# Level is set to [90], which means that it will compute the 90% prediction interval
fcst_df = sf.forecast(df=Y_df, h=28, level=[90])

# Get the current time after the forecasting ends
end = time()

# Calculate and print the total time taken for the forecasting in minutes
print(f'Forecast Minutes: {(end - init) / 60}')
Copy code
Exception: You must pass `prediction_intervals` to compute them.
Q: How should I modify the models for this to work? Should I add the Conformal Intervals somehow. (Many statistical models have conf intervals out of box?) Thank you and have a great day.
❤️ 1
Alright I figured it out (maybe) 🙂
Copy code
horizon = 28
models = [
    SeasonalNaive(season_length=7, prediction_intervals=ConformalIntervals(n_windows=5, h=28)),
    Naive(prediction_intervals=ConformalIntervals(n_windows=5, h=28)),
    HistoricAverage(prediction_intervals=ConformalIntervals(n_windows=5, h=28)),
    CrostonOptimized(prediction_intervals=ConformalIntervals(n_windows=5, h=28)),
    ADIDA(prediction_intervals=ConformalIntervals(n_windows=5, h=28)),
    IMAPA(prediction_intervals=ConformalIntervals(n_windows=5, h=28)),
    AutoETS(season_length=7, prediction_intervals=ConformalIntervals(n_windows=5, h=28))
with n_windows however it takes some solid time extra ;D, is there more reading to what hyperparameter makes sense for n_windows ? Thanks.
Ok no I have not figured it out:
cs[i_window] = np.abs(fcst_window["mean"] - y_test)
if I add preduction intervals as follows
Copy code
CrostonOptimized(prediction_intervals=ConformalIntervals(n_windows=5, h=28))
I get:
ValueError: operands could not be broadcast together with shapes (28,) (15,)
Q: How do I make statsforecast models predict with intervals ?

José Morales

10/05/2023, 3:28 PM
Hey. You only need to provide prediction_intervals for models that don't support them out of the box, so for example AutoETS should work without it (but you can also compute them using conformal intervals if you want). Does the error only happen for croston? It seems like it's a short serie, can you try reducing n_windows? The n_windows parameter controls how many CV iterations are performed to estimate the errors and build the intervals, you can try 4 for example and it should work well
👀 1


10/05/2023, 5:19 PM
Thanks for super quick answer.