For your code got the error: 21:15:22 - cmdstanpy - INFO - Chain [1] start processing
21:15:22 - cmdstanpy - INFO - Chain [1] done processing
Trial 0 failed with parameters: {'changepoint_prior_scale': 0.0065357708994127, 'seasonality_prior_scale': 4.467801192990704, 'changepoint_range': 0.8807921358128056, 'n_changepoints': 25, 'seasonality_mode': 'multiplicative', 'interval_width': 0.9234873634389699} because of the following error: ValueError('operands could not be broadcast together with shapes (365,) (261,) ').
Traceback (most recent call last):
File "/home/jupyter-00061883/.local/lib/python3.12/site-packages/optuna/study/_optimize.py", line 201, in _run_trial
value_or_values = func(trial)
^^^^^^^^^^^
File "/tmp/ipykernel_1312743/1396139231.py", line 45, in objective
smape_score = smape(test_df_weekdays['y'].values, fcst_holdout['yhat'].values)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/ipykernel_1312743/2342680163.py", line 3, in smape
return np.mean(2*np.abs(pred-actual) / (np.abs(actual)+np.abs(pred))) * 100
~~~~^~~~~~~
ValueError: operands could not be broadcast together with shapes (365,) (261,)
Trial 0 failed with value None.
ValueError Traceback (most recent call last)
Cell In[26], line 51
49 # Run Bayesian optimization
50 study = optuna.create_study(direction='minimize')
---> 51 study.optimize(objective, n_trials=50)
53 # Get the best parameters
54 best_params = study.best_params
File ~/.local/lib/python3.12/site-packages/optuna/study/study.py:489, in Study.optimize(self, func, n_trials, timeout, n_jobs, catch, callbacks, gc_after_trial, show_progress_bar)
387 def optimize(
388 self,
389 func: ObjectiveFuncType,
(...) 396 show_progress_bar: bool = False,
397 ) -> None:
398 """Optimize an objective function.
399
400 Optimization is done by choosing a suitable set of hyperparameter values from a given
(...) 487 If nested invocation of this method occurs.
488 """
--> 489 _optimize(
490 study=self,
491 func=func,
492 n_trials=n_trials,
493 timeout=timeout,
494 n_jobs=n_jobs,
495 catch=tuple(catch) if isinstance(catch, Iterable) else (catch,),
496 callbacks=callbacks,
497 gc_after_trial=gc_after_trial,
498 show_progress_bar=show_progress_bar,
499 )
File ~/.local/lib/python3.12/site-packages/optuna/study/_optimize.py:64, in _optimize(study, func, n_trials, timeout, n_jobs, catch, callbacks, gc_after_trial, show_progress_bar)
62 try:
63 if n_jobs == 1:
---> 64 _optimize_sequential(
65 study,
66 func,
67 n_trials,
68 timeout,
69 catch,
70 callbacks,
71 gc_after_trial,
72 reseed_sampler_rng=False,
73 time_start=None,
74 progress_bar=progress_bar,
75 )
76 else:
77 if n_jobs == -1:
File ~/.local/lib/python3.12/site-packages/optuna/study/_optimize.py:161, in _optimize_sequential(study, func, n_trials, timeout, catch, callbacks, gc_after_trial, reseed_sampler_rng, time_start, progress_bar)
158 break
160 try:
--> 161 frozen_trial = _run_trial(study, func, catch)
162 finally:
163 # The following line mitigates memory problems that can be occurred in some
164 # environments (e.g., services that use computing containers such as GitHub Actions).
165 # Please refer to the following PR for further details:
166 # https://github.com/optuna/optuna/pull/325.
167 if gc_after_trial:
File ~/.local/lib/python3.12/site-packages/optuna/study/_optimize.py:253, in _run_trial(study, func, catch)
246 assert False, "Should not reach."
248 if (
249 frozen_trial.state == TrialState.FAIL
250 and func_err is not None
251 and not isinstance(func_err, catch)
252 ):
--> 253 raise func_err
254 return frozen_trial
File ~/.local/lib/python3.12/site-packages/optuna/study/_optimize.py:201, in _run_trial(study, func, catch)
199 with get_heartbeat_thread(trial._trial_id, study._storage):
200 try:
--> 201 value_or_values = func(trial)
202 except exceptions.TrialPruned as e:
203 # TODO(mamu): Handle multi-objective cases.
204 state = TrialState.PRUNED
Cell In[26], line 45, in objective(trial)
43 # Evaluate the model using SMAPE
44 test_df_weekdays = test_df[test_df['ds'].dt.weekday < 5].copy()
---> 45 smape_score = smape(test_df_weekdays['y'].values, fcst_holdout['yhat'].values)
47 return smape_score
Cell In[23], line 3, in smape(actual, pred)
1 def smape(actual, pred):
2 """Symmetric MAPE (%)"""
----> 3 return np.mean(2*np.abs(pred-actual) / (np.abs(actual)+np.abs(pred))) * 100
ValueError: operands could not be broadcast together with shapes (365,) (261,)