*Dataset*
indexeddataset=dataset[['Date','Close']]
indexeddataset.set_index('Date', inplace = True)
indexeddataset.index=pd.to_datetime(indexeddataset.index) *Set index*
indexeddataset=indexeddataset.resample('1M').mean() *Resample monthly basis*
indexeddataset_log = np.log(indexeddataset) *Log Transformation*
print(indexeddataset_log.head())
*Print the data*
Close
Date
2007-01-31 37.563000
2007-02-28 39.495263
2007-03-31 38.655909
2007-04-30 46.629500
2007-05-31 64.559091
*After performing data stationarity and calculating acf and pacf values, perform arima model for forecasting
ARIMA MODEL*
model = ARIMA(indexeddataset_log, order = (2,1,2))
result_ARIMA= model.fit(disp=-1)
plt.plot(datasetLogShift)
plt.plot(result_ARIMA.fittedvalues, color='red')
plt.title('RSS: %.4f'% sum((result_ARIMA.fittedvalues-datasetLogShift['Close'])**2))
print('Plotting ARIMA model')
Prediction_ARIMA = pd.Series(result_ARIMA.fittedvalues, copy=True)
Prediction_ARIMA.head()
Prediction_ARIMA_cumsum = Prediction_ARIMA.cumsum()
Prediction_ARIMA.head()
predictions_ARIMA_log = pd.Series(indexeddataset_log['Close'].iloc[0], index=indexeddataset_log.index)
predictions_ARIMA_log= predictions_ARIMA_log.add(Prediction_ARIMA_cumsum, fill_value=0)
predictions_ARIMA_log.head()
predictions_ARIMA = np.exp(predictions_ARIMA_log)
plt.figure(figsize=(15,7))
plt.plot(indexeddataset)
plt.plot(predictions_ARIMA, label='Predicted')
plt.legend()
plt.show()
*Predictions*
result_ARIMA.plot_predict(1,156)
x = result_ARIMA.forecast(steps=72)
print(x)
有人可以帮助我如何预测预测值并使用原始值与日期(而非对数刻度值)进行绘图 我用对数刻度绘制了该图。我想将其转换为原始格式。如何在ARIMA模型中做到这一点?我感谢您的帮助。谢谢