如何在python-ARIMA中预测未来价值

2022-09-28 21:34:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直在研究基于ARIMA模型的时间序列。但我试着预测未来的价值。例如,我的时间序列结束于:2015-11-01,此时我想预测2015-12-01的值。我曾在网上搜索过,但对未来一无所知值。全部文档和互联网上的例子只显示了测试预测。事实上,很少有关于未来价值的网站,但是,所有的例子都是用旧的日期写的。当然,我在这里搜索了一下,但还是什么也没找到。你知道吗

import pandas as pd 
import numpy as np 

data = pd.read_csv(r'Desktop/IPG2211A2N.csv', index_col = 0)

#TURN INDEX TO DATETIME *IMPORTANT.
data.index = pd.to_datetime(data.index)
data.columns = ['Energy Production']

import pmdarima as pm
stepwise_model = pm.auto_arima(data, start_p=1, start_q=1,
                           max_p=3, max_q=3, m=12,
                           start_P=0, seasonal=True,
                           d=1, D=1, trace=True,
                           error_action='ignore',  
                           suppress_warnings=True, 
                           stepwise=True)

# =============================================================================
# TRAIN
# =============================================================================
train = data.iloc[:int(len(data)*0.7),:]
test = data.iloc[int(len(data)*0.7):,:]
stepwise_model.fit(train)

# =============================================================================
# FORECAST
# =============================================================================
future_forecast = stepwise_model.predict(n_periods=len(test))
future_forecast = pd.DataFrame(future_forecast,index = test.index,columns=['Prediction'])

# =============================================================================
# COMPARE RESULT BETWEEN JUST TEST AND RESULT
# =============================================================================
import matplotlib.pyplot as plt 
plt.plot(pd.concat([test,future_forecast],axis=1))
plt.show()


# =============================================================================
# COMPARE RESULT BETWEEN ALL DATA AND RESULT
# =============================================================================
plt.cla()
future_forecast2 = future_forecast
plt.plot(pd.concat([data,future_forecast2],axis=1))
plt.show()

Tags: testimporttruedataindexmodellenasfuturepltresultstartpdstepwiseforecast