我正在寻找AIC最低的型号。我无法使函数返回模型的AIC最低。下面的代码演示了我遇到的困难。
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))]
parameters = []
for param in pdq:
for param_seasonal in seasonal_pdq:
try:
model=sm.tsa.statespace.SARIMAX(y_hat,method='css',order=param,
seasonal_order = param_seasonal,enforce_stationarity=False
enforce_invertibility=False)
results = model.fit()
print('ARIMA{}x{}12 - AIC:
{}'.format(param,param_seasonal,results.aic))
except:
continue
aic = results.aic
parameters.append([param,param_seasonal,aic])
result_table = pd.DataFrame(parameters)
result_table.columns = ['parameters','parameters_seasonal','aic']
result_table = result_table.sort_values(by='aic',ascending = True).reset_index(drop = True)
答案 0 :(得分:1)
请尝试以下代码。希望他们能为您效劳!
parameters = []
for param in pdq:
for param_seasonal in seasonal_pdq:
try:
mod = sm.tsa.statespace.SARIMAX(df_final,
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
aic = results.aic
parameters.append([param,param_seasonal,aic])
result_table = pd.DataFrame(parameters)
result_table.columns = ['parameters', 'parameters_seasonal','aic']
result_table = result_table.sort_values(by='aic',ascending = True).reset_index(drop = True)
minimum = result_table['aic'].min()
a = result_table.loc[result_table['aic'] == minimum]
print(' The best combination that gives the lowest AIC is:')
print(a)