1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
Description: Fix regressor validation with scikit-learn ≥ 1.6
Avoid calling is_regressor() on None or invalid objects,
which raises AttributeError with scikit-learn ≥ 1.6 due
to the new tag system. Reorder the check and normalize
failures to ValueError, restoring expected behavior and
fixing test failures.
Forwarded: https://github.com/holgern/scikit-optimize/issues/11
Author: Yogeswaran Umasankar <yogu@debian.org>
Last-Update: 2026-02-16
--- a/skopt/optimizer/optimizer.py
+++ b/skopt/optimizer/optimizer.py
@@ -253,8 +253,13 @@ class Optimizer:
)
# check if regressor
- if not is_regressor(base_estimator) and base_estimator is not None:
- raise ValueError("%s has to be a regressor." % base_estimator)
+ if base_estimator is not None and not isinstance(base_estimator, str):
+ try:
+ ok = is_regressor(base_estimator)
+ except Exception:
+ ok = False
+ if not ok:
+ raise ValueError("base_estimator has to be a regressor.")
# treat per second acqusition function specially
is_multi_regressor = isinstance(base_estimator, MultiOutputRegressor)
|