Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SARIMA
#1
Hello,
I'm trying to get the predictions for 6 months instead for 12 months, can you help me to change it ?
Please find below the sarima code for predictions for 12 months :

## Getting the order of the iterations with minimum AIC score
order = lst_df.loc[lst_df[2].idxmin()][0]
## Getting the seasonal order of the iterations with minimum AIC score
seasonal_order = lst_df.loc[lst_df[2].idxmin()][1]

## Using the parameters that have the lowest AIC score to predict for the following year
mod = sm.tsa.statespace.SARIMAX(y,
order=(order[0],1,order[1]),
seasonal_order=(seasonal_order[0],1,seasonal_order[1], 12),
enforce_stationarity=True,
enforce_invertibility=True)

## Fit the results
results = mod.fit()

## Getting the start and end dates for what we are trying to predict. It shouldn't be this hard,
## but I suspect there is a bug in the SARIMAX code and the below is a workaround.
start = ((pd.datetime(year,1,1).year - y.index[0].year)*months_to_predict +
(pd.datetime(year,1,1).month - y.index[0].month))
end = start + (months_to_predict-1)


## These are the results of the predictions
df_temp = pd.DataFrame(results.get_prediction(start = start, end = end, dynamic=False).predicted_mean)

## Setting the proper date indices
date_index = pd.date_range(pd.datetime(year,1,1).strftime('%m/%d/%Y'), periods = months_to_predict,
freq = pd.offsets.MonthBegin(1))
## These are the predictions with the proper date indices
predictions = df_temp.set_index(date_index)[0]
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020