我是python的新手,并且正在编写将ARIMA测试结果输入到数据框的过程。所以,我通过以下编码获得了ARIMA结果:
for param in pdq:
for param_seasonal in seasonal_pdq:
try:
mod = sm.tsa.statespace.SARIMAX(df_month.Weighted_Price_box,
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))
data = {'parameters' : [param], 'aic' : [results.aic]}
except:
continue
rt=pd.DataFrame(data)
rt
输出结果为:
ARIMA(0, 0, 0)x(0, 0, 1, 12)12 - AIC:407.22578000041864
ARIMA(0, 0, 0)x(0, 1, 1, 12)12 - AIC:238.18574141909036
ARIMA(0, 0, 0)x(1, 0, 0, 12)12 - AIC:294.4619377438503
ARIMA(0, 0, 0)x(1, 0, 1, 12)12 - AIC:293.02415782731146
ARIMA(0, 0, 0)x(1, 1, 0, 12)12 - AIC:247.3954939335222
ARIMA(0, 0, 0)x(1, 1, 1, 12)12 - AIC:240.81509476560723
ARIMA(0, 0, 1)x(0, 0, 0, 12)12 - AIC:424.3477569952406
ARIMA(0, 0, 1)x(0, 0, 1, 12)12 - AIC:322.92052137636273
ARIMA(0, 0, 1)x(0, 1, 0, 12)12 - AIC:230.11538217516411
ARIMA(0, 0, 1)x(0, 1, 1, 12)12 - AIC:168.44268972392362
ARIMA(0, 0, 1)x(1, 0, 0, 12)12 - AIC:221.44384124449488
ARIMA(0, 0, 1)x(1, 0, 1, 12)12 - AIC:201.34872206655223
ARIMA(0, 0, 1)x(1, 1, 0, 12)12 - AIC:189.5734656288126
......
aic parameters
0 57.95076 (1, 1, 1)
如您所见,我的名为rt的数据框只包含一行而不是13行。
答案 0 :(得分:1)
使用列表附加内容并使用它来创建DF。
<强>实施例强>
data = []
for param in pdq:
for param_seasonal in seasonal_pdq:
try:
mod = sm.tsa.statespace.SARIMAX(df_month.Weighted_Price_box,
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))
data.append({'parameters' : [param], 'aic' : [results.aic]})
except:
continue
rt=pd.DataFrame(data)
rt