'print statement takes many seconds to show up in console, why?
I've got some code that should do a cross validated hyper parameter search of a Prophet timeseries model and I've run into an interesting quirk:
param_grid = {
'changepoint_prior_scale': [0.01, 0.5],
'seasonality_prior_scale': [0.1, 10.0],
'holidays_prior_scale': [0.1, 10.0]
}
# Generate all combinations of parameters
all_params = [dict(zip(param_grid.keys(), v)) for v in itertools.product(*param_grid.values())]
rmses = [] # Store the RMSEs for each params here
for i, params in enumerate(all_params):
print(f'starting {i} out of {len(all_params)}')
m_ = Prophet(
holidays = holidays_p,
**params
)
m_.fit(df)
df_cv = cross_validation(m_, initial = '370 days', horizon='60 days', parallel="processes")
df_p = performance_metrics(df_cv, rolling_window=1)
rmses.append(df_p['rmse'].values[0])
It takes upward of 30 seconds for the print statement to appear in my console (I'm using Spyder). Why? Its the first thing in the loop.
I was working under the impression that the kernel will execute the for loop's code top to bottom repeatedly, so what could possibly cause it to take to long?
Just running this:
for i, params in enumerate(all_params):
print(f'starting {i} out of {len(all_params)}')
Behaves as expected, instant prints of i and the length of params.
Any ideas? Am I mistaken about python's for loop functioning?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
