Skip to content

Instantly share code, notes, and snippets.

@marcosan93
Created September 26, 2019 21:43
Show Gist options
  • Select an option

  • Save marcosan93/12180986b6a48a64256e2d3239b3e1d7 to your computer and use it in GitHub Desktop.

Select an option

Save marcosan93/12180986b6a48a64256e2d3239b3e1d7 to your computer and use it in GitHub Desktop.
def best_param(model, data, pdq, pdqs):
"""
Loops through each possible combo for pdq and pdqs
Runs the model for each combo
Retrieves the model with lowest AIC score
"""
ans = []
for comb in tqdm(pdq):
for combs in tqdm(pdqs):
try:
mod = model(data,
order=comb,
seasonal_order=combs,
enforce_stationarity=False,
enforce_invertibility=False,
freq='D')
output = mod.fit()
ans.append([comb, combs, output.aic])
except:
continue
ans_df = pd.DataFrame(ans, columns=['pdq', 'pdqs', 'aic'])
return ans_df.loc[ans_df.aic.idxmin()]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment