Skip to content

Instantly share code, notes, and snippets.

@dpbac
Created July 2, 2021 15:43
Show Gist options
  • Select an option

  • Save dpbac/98e806e6608cb6f01ba0b222c54e2a20 to your computer and use it in GitHub Desktop.

Select an option

Save dpbac/98e806e6608cb6f01ba0b222c54e2a20 to your computer and use it in GitHub Desktop.
import itertools
param_grid = {
'changepoint_prior_scale': [0.001, 0.01, 0.1, 0.5],
'seasonality_prior_scale': [0.01, 0.1, 1.0, 10.0],
}
# Generate all combinations of parameters
all_params = [dict(zip(param_grid.keys(), v)) for v in itertools.product(*param_grid.values())]
maes = [] # Store the MAE for each params here
mapes = [] # Store the MAPE for each params here
# Use cross validation to evaluate all parameters
for params in all_params:
m = Prophet(**params).fit(df_store_2_item_28) # Fit model with given params
df_cv = cross_validation(m, horizon='90 days', parallel="processes")
df_p = performance_metrics(df_cv, rolling_window=1)
maes.append(df_p['mae'].values[0])
mapes.append(df_p['mape'].values[0])
# Find the best parameters
tuning_results = pd.DataFrame(all_params)
tuning_results['mae'] = maes
tuning_results['mape'] = mapes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment