简体   繁体   中英

ARIMA prediction validtion

I am running validation on a ARIMA model and while the code executes, the plot is not correct. I hav tried to change the parameters with no luck, something is causing the data for the x axis to not plot correctly.

Sample of dataset:

Date    consume forecast
2017-01-01  122 141
2017-02-01  122 141
2017-03-01  122 141
2017-04-01  122 141
2017-05-01  122 141
2017-06-01  122 141
2017-07-01  122 141
2017-08-01  122 141
2017-09-01  10  340
2017-10-01  36  46
2017-11-01  268 141
2017-12-01  176 37
2018-01-01  2293 746
2018-02-01  958 12
2018-03-01  305 12
2018-04-01  179 80
2018-05-01  259 12
2018-06-01  173 5486
2018-07-01  821 276
2018-08-01  438 746
2018-09-01  825 746
2018-10-01  768 84
2018-11-01  2191 746
2018-12-01  897 12
2019-01-01  1147 3688
2019-02-01  393 4905
2019-03-01  736 1294
2019-04-01  1269 1015
2019-05-01  1594 419

Code:

p = d = q = range(0, 2)
pdq = list(itertools.product(p, d, q))
seasonal_pdq = [(x[0], x[1], x[2], 12) for x in list(itertools.product(p, d, q))]

print('Examples of parameter combinations for Seasonal ARIMA...')
print('SARIMAX: {} x {}'.format(pdq[1], seasonal_pdq[1]))
print('SARIMAX: {} x {}'.format(pdq[1], seasonal_pdq[2]))
print('SARIMAX: {} x {}'.format(pdq[2], seasonal_pdq[3]))
print('SARIMAX: {} x {}'.format(pdq[2], seasonal_pdq[4]))

for param in pdq:
    for param_seasonal in seasonal_pdq:
        try:
            mod = sm.tsa.statespace.SARIMAX(y,order=param,seasonal_order=param_seasonal,enforce_stationarity=False,enforce_invertibility=False)


            results = mod.fit()

            print('ARIMA{}x{}12 - AIC:{}'.format(param, param_seasonal, results.aic))
        except:
            continue

mod = sm.tsa.statespace.SARIMAX(y,
                                order=(1, 1, 1),
                                seasonal_order=(1, 1, 1, 12),
                                enforce_invertibility=False)
results = mod.fit()
print(results.summary().tables[1])

results.plot_diagnostics(figsize=(15, 12))
plt.show()

pred = results.get_prediction(start=pd.to_datetime('2020-01'), dynamic=False)
pred_ci = pred.conf_int()
ax = y['2017-01':].plot(label='Actual')
pred.predicted_mean.plot(ax=ax, label='Predicted - Test', alpha=.7, figsize=(14, 7))
ax.fill_between(pred_ci.index,
                pred_ci.iloc[:, 0],
                pred_ci.iloc[:, 1], color='k', alpha=.2)
ax.set_xlabel('Date')
ax.set_ylabel('Forecasted vCPU')
plt.legend()
plt.show()

What is expected is similar to this:

在此处输入图像描述

what I get is this:

在此处输入图像描述

corrected issue by reformatting Date column prior to running ARIMA code:

data['Date']=pd.to_datetime(data['Date'])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM