问题
I'm trying to get a "fuzzy" prediction of a timeseries, using an SARIMA model
My training set is prices_train
, and the model is built as follows:
model_order = (0, 1, 1)
model_seasonal_order = (2, 1, 1, 24)
model = sm.tsa.statespace.SARIMAX(
prices_train, order=model_order,
seasonal_order=model_seasonal_order)
model_fit = model.fit(disp=0)
I know I can get a point forecast using this instruction:
pred = model_fit.forecast(3)
But I don't want a point forecast, I want a confidence interval of each predicted value so I can have a fuzzy timeseries of predicted values
I've seen tutorials such as this one, where they apply this code:
forecast, stderr, conf = model_fit.forecast(alpha=a)
However, it seems the library has been updated since 2017, because that does not work. I've read the statsmodels
manual but I haven't found much help.
回答1:
Your fit model should have a get_prediction() function that returns a prediction.
Then you can call prediction.conf_int(alpha=a)
.
回答2:
Well I've found a way, I'll post it here in case anyone reading this in 2035 needs it:
Being h
the number of predictions:
conf_ins = model_fit.get_forecast(h).summary_frame()
It returns a dataframe with the confidence interval of h predictions, indicating for each one:
- Average
- Mean squared error
- Minimum
- Maximum
来源:https://stackoverflow.com/questions/63453156/how-to-get-the-confidence-interval-of-each-prediction-on-an-arima-model