Skip to content

Commit 4eeea90

Browse files
authored
[DOC] improved docstrings for estimator tuners in integrations module (#172)
This PR adds clarification to the documentation of estimator tuners in the `integrations` module.
1 parent 0595bd5 commit 4eeea90

2 files changed

Lines changed: 77 additions & 7 deletions

File tree

src/hyperactive/integrations/sklearn/opt_cv.py

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,40 @@
1515

1616

1717
class OptCV(BaseEstimator, _BestEstimator_, Checks):
18-
"""Tuning via any optimizer in the hyperactive API.
18+
"""Tuning an sklearn estimator via any optimizer in the hyperactive toolbox.
19+
20+
``OptCV`` uses any available tuning engine from ``hyperactive``
21+
to tune an sklearn estimator via cross-validation.
22+
23+
It passes cross-validation results as scores to the tuning engine,
24+
which identifies the best hyperparameters.
25+
26+
Any available tuning engine from hyperactive can be used, for example:
27+
28+
* grid search - ``from hyperactive.opt import GridSearchSk as GridSearch``,
29+
this results in the same algorithm as ``GridSearchCV``
30+
* hill climbing - ``from hyperactive.opt import HillClimbing``
31+
* optuna parzen-tree search - ``from hyperactive.opt.optuna import TPEOptimizer``
32+
33+
Configuration of the tuning engine is as per the respective documentation.
34+
35+
Formally, ``OptCV`` does the following:
36+
37+
In ``fit``:
38+
39+
* wraps the ``estimator``, ``scoring``, and other parameters
40+
into a ``SklearnCvExperiment`` instance, which is passed to the optimizer
41+
``optimizer`` as the ``experiment`` argument.
42+
* Optimal parameters are then obtained from ``optimizer.solve``, and set
43+
as ``best_params_`` and ``best_estimator_`` attributes.
44+
* If ``refit=True``, ``best_estimator_`` is fitted to the entire ``X`` and ``y``.
45+
46+
In ``predict`` and ``predict``-like methods, calls the respective method
47+
of the ``best_estimator_`` if ``refit=True``.
1948
2049
Parameters
2150
----------
22-
estimator : SklearnBaseEstimator
51+
estimator : sklearn BaseEstimator
2352
The estimator to be tuned.
2453
optimizer : hyperactive BaseOptimizer
2554
The optimizer to be used for hyperparameter search.
@@ -40,7 +69,13 @@ class OptCV(BaseEstimator, _BestEstimator_, Checks):
4069
4170
Example
4271
-------
43-
Tuning sklearn SVC via grid search
72+
Any available tuning engine from hyperactive can be used, for example:
73+
74+
* grid search - ``from hyperactive.opt import GridSearchSk as GridSearch``
75+
* hill climbing - ``from hyperactive.opt import HillClimbing``
76+
* optuna parzen-tree search - ``from hyperactive.opt.optuna import TPEOptimizer``
77+
78+
For illustration, we use grid search, this can be replaced by any other optimizer.
4479
4580
1. defining the tuned estimator:
4681
>>> from sklearn.svm import SVC

src/hyperactive/integrations/sktime/_forecasting.py

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,36 @@
1414

1515

1616
class ForecastingOptCV(_DelegatedForecaster):
17-
"""Tune an sktime forecaster via any optimizer in the hyperactive API.
17+
"""Tune an sktime forecaster via any optimizer in the hyperactive toolbox.
18+
19+
``ForecastingOptCV`` uses any available tuning engine from ``hyperactive``
20+
to tune a forecaster by backtesting.
21+
22+
It passes backtesting results as scores to the tuning engine,
23+
which identifies the best hyperparameters.
24+
25+
Any available tuning engine from hyperactive can be used, for example:
26+
27+
* grid search - ``from hyperactive.opt import GridSearchSk as GridSearch``,
28+
this results in the same algorithm as ``ForecastingGridSearchCV``
29+
* hill climbing - ``from hyperactive.opt import HillClimbing``
30+
* optuna parzen-tree search - ``from hyperactive.opt.optuna import TPEOptimizer``
31+
32+
Configuration of the tuning engine is as per the respective documentation.
33+
34+
Formally, ``ForecastingOptCV`` does the following:
35+
36+
In ``fit``:
37+
38+
* wraps the ``forecaster``, ``scoring``, and other parameters
39+
into a ``SktimeForecastingExperiment`` instance, which is passed to the optimizer
40+
``optimizer`` as the ``experiment`` argument.
41+
* Optimal parameters are then obtained from ``optimizer.solve``, and set
42+
as ``best_params_`` and ``best_forecaster_`` attributes.
43+
* If ``refit=True``, ``best_forecaster_`` is fitted to the entire ``y`` and ``X``.
44+
45+
In ``predict`` and ``predict``-like methods, calls the respective method
46+
of the ``best_forecaster_`` if ``refit=True``.
1847
1948
Parameters
2049
----------
@@ -124,7 +153,13 @@ class ForecastingOptCV(_DelegatedForecaster):
124153
125154
Example
126155
-------
127-
Tuning an sktime forecaster via grid search
156+
Any available tuning engine from hyperactive can be used, for example:
157+
158+
* grid search - ``from hyperactive.opt import GridSearchSk as GridSearch``
159+
* hill climbing - ``from hyperactive.opt import HillClimbing``
160+
* optuna parzen-tree search - ``from hyperactive.opt.optuna import TPEOptimizer``
161+
162+
For illustration, we use grid search, this can be replaced by any other optimizer.
128163
129164
1. defining the tuned estimator:
130165
>>> from sktime.forecasting.naive import NaiveForecaster
@@ -151,9 +186,9 @@ class ForecastingOptCV(_DelegatedForecaster):
151186
ForecastingOptCV(...)
152187
>>> y_pred = tuned_naive.predict()
153188
154-
3. obtaining best parameters and best estimator
189+
3. obtaining best parameters and best forecaster
155190
>>> best_params = tuned_naive.best_params_
156-
>>> best_estimator = tuned_naive.best_forecaster_
191+
>>> best_forecaster = tuned_naive.best_forecaster_
157192
"""
158193

159194
_tags = {

0 commit comments

Comments
 (0)