当我尝试按correct wat to use ARMAResults.predict() function中的建议实现代码时。如下
import numpy as np
import scipy as stats
import pandas as pd
from pandas import Series,DataFrame
import statsmodels.api as sm
dates=pd.date_range('2011-1-30','2011-04-30')
dataseries=Series([22,624,634,774,726,752,38,534,722,678,750,690,686,26,708,606,632,632,632,584,28,576,474
,536,512,464,436,24,448,408,528,602,638,640,26,658,548,620,534,422,482,26,616,612,622,598,614,614,24,644,506,522,622,526,26,22,738
,582,592,408,466,568,44,680,652,598,642,714,562,38,778,796,742,460,610,42,38,732,650,670,618,574,42,22,610,456,22,630,408,390,24
],index=dates)
df=pd.DataFrame({'Consumption':dataseries})
df
INPUT_DATA_POINT = len(df)
P = 1
Q = 0
result = sm.tsa.ARMA(df[:INPUT_DATA_POINT], (P, Q))
start_pos = max(result.k_ar, result.k_ma)
fit = []
for t in range(start_pos, len(df)):
value = 0
for i in range(1, result.k_ar + 1):
value += result.arparams[i - 1] * df[t - i]
for i in range(1, result.k_ma + 1):
value += result.maparams[i - 1] * df[t - i]
fit.append(value)
fit = result.predict(0, len(data))
# Plot
plt.figure(facecolor='white')
plt.plot(df, 'b-', label='data')
plt.plot(range(INPUT_DATA_POINT), result.fittedvalues, 'r+', label='fit')
plt.plot(range(start_pos, len(df)), fit, 'r-', label='predict')
plt.legend(loc=4)
plt.show()
我收到如下属性错误
14 for i in range(1, result.k_ma + 1):
15 value += result.maparams[i - 1] * df[t - i]
AttributeError: 'ARMA' object has no attribute 'arparams'
如何克服这个错误。