Skip to content

Commit 8e99f8b

Browse files
committed
add docstring + fix tests
1 parent c2dec2c commit 8e99f8b

1 file changed

Lines changed: 47 additions & 13 deletions

File tree

src/hyperactive/experiment/integrations/lightgbm_experiment.py

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,52 @@
88
class LightGBMExperiment(SklearnCvExperiment):
99
"""Experiment adapter for LightGBM cross-validation experiments.
1010
11-
Thin wrapper around SklearnCvExperiment for LightGBM estimators.
12-
13-
LightGBM estimators follow the sklearn API, so this class does not
14-
add new functionality beyond SklearnCvExperiment. It exists for
15-
discoverability and explicit LightGBM support.
11+
Thin wrapper around ``SklearnCvExperiment`` for LightGBM estimators.
12+
LightGBM's sklearn-compatible API (``LGBMClassifier``, ``LGBMRegressor``)
13+
works without adaptation. This class exists for discoverability, explicit
14+
soft-dependency tracking via the ``python_dependencies`` tag, and as an
15+
extension point for future LightGBM-specific behavior.
16+
17+
Parameters
18+
----------
19+
estimator : LGBMClassifier or LGBMRegressor
20+
The LightGBM estimator to evaluate. Any sklearn-compatible estimator
21+
is accepted, but LightGBM estimators are the intended use case.
22+
X : array-like, shape (n_samples, n_features)
23+
Input data.
24+
y : array-like, shape (n_samples,)
25+
Target values.
26+
scoring : callable or str, default=None
27+
Scoring function. Defaults follow ``SklearnCvExperiment`` conventions:
28+
``accuracy_score`` for classifiers, ``mean_squared_error`` for
29+
regressors.
30+
cv : int or cross-validation generator, default=KFold(n_splits=3, shuffle=True)
31+
Cross-validation strategy.
32+
33+
Notes
34+
-----
35+
LightGBM prints training logs to stdout by default. Pass
36+
``verbosity=-1`` to the estimator constructor to suppress this output.
37+
38+
For all remaining parameter details see ``SklearnCvExperiment``.
39+
40+
Examples
41+
--------
42+
>>> from hyperactive.experiment.integrations import LightGBMExperiment
43+
>>> from lightgbm import LGBMClassifier
44+
>>> from sklearn.datasets import load_iris
45+
>>> X, y = load_iris(return_X_y=True)
46+
>>> exp = LightGBMExperiment(
47+
... estimator=LGBMClassifier(verbosity=-1),
48+
... X=X,
49+
... y=y,
50+
... )
51+
>>> params = {"n_estimators": 50, "max_depth": 3}
52+
>>> score, metadata = exp.score(params)
1653
"""
1754

1855
_tags = {
56+
"authors": ["kajal-jotwani"],
1957
"python_dependencies": "lightgbm",
2058
}
2159

@@ -30,19 +68,17 @@ def get_test_params(cls, parameter_set="default"):
3068
from lightgbm import LGBMClassifier, LGBMRegressor
3169
from sklearn.datasets import load_diabetes, load_iris
3270

33-
# Classification test case
3471
X, y = load_iris(return_X_y=True)
3572
params0 = {
36-
"estimator": LGBMClassifier(n_estimators=10),
73+
"estimator": LGBMClassifier(n_estimators=10, verbosity=-1),
3774
"X": X,
3875
"y": y,
3976
"cv": 2,
4077
}
4178

42-
# Regression test case
4379
X, y = load_diabetes(return_X_y=True)
4480
params1 = {
45-
"estimator": LGBMRegressor(n_estimators=10),
81+
"estimator": LGBMRegressor(n_estimators=10, verbosity=-1),
4682
"X": X,
4783
"y": y,
4884
"cv": 2,
@@ -58,7 +94,5 @@ def _get_score_params(cls):
5894
if not _check_soft_dependencies("lightgbm", severity="none"):
5995
return []
6096

61-
val0 = {"n_estimators": 5, "max_depth": 2}
62-
val1 = {"n_estimators": 5, "max_depth": 2}
63-
64-
return [val0, val1]
97+
score_params = {"n_estimators": 5, "max_depth": 2}
98+
return [score_params, score_params]

0 commit comments

Comments
 (0)