Skip to content

Commit 8dbb243

Browse files
authored
[DOC] Add docstrings for best_estimator.py (#235)
## Description This PR adds docstrings for `best_estimator.py`, from https://github.com/scikit-learn/scikit-learn/blob/main/sklearn/model_selection/_search.py ## Related Issues Fixes #226 ## Type of Change <!-- Mark the applicable option with [x] --> - [ ] `[BUG]` - Bug fix (non-breaking change fixing an issue) - [ ] `[ENH]` - New feature (non-breaking change adding functionality) - [x] `[DOC]` - Documentation changes - [ ] `[MNT]` - Maintenance ## How was this solved? <!-- Explain your approach to solving the issue --> ## Checklist - [x] PR title includes appropriate tag: `[BUG]`, `[ENH]`, `[DOC]` or `[MNT]` - [x] Linked to related issue (if applicable) - [ ] Code passes `make check` (lint, format, isort) ## Note @SimonBlanke `make check` is failing because of unused imports, unorganized imports and other issues... Can I take that up too? ``` Found 90 errors. [*] 67 fixable with the `--fix` option (1 hidden fix can be enabled with the `--unsafe-fixes` option). make: *** [lint] Error 1 ```
1 parent 8faa034 commit 8dbb243

1 file changed

Lines changed: 125 additions & 7 deletions

File tree

‎src/hyperactive/integrations/sklearn/best_estimator.py‎

Lines changed: 125 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,43 +20,161 @@ class BestEstimator:
2020

2121
@available_if(_estimator_has("score_samples"))
2222
def score_samples(self, X):
23-
"""Score Samples function."""
23+
"""Call score_samples on the estimator with the best found parameters.
24+
25+
Only available if ``refit=True`` and the underlying estimator supports
26+
``score_samples``.
27+
28+
Parameters
29+
----------
30+
X : iterable
31+
Data to predict on. Must fulfill input requirements
32+
of the underlying estimator.
33+
34+
Returns
35+
-------
36+
y_score : ndarray of shape (n_samples,)
37+
Score per sample for `X` based on the estimator with the best found
38+
parameters (e.g. log-likelihood, anomaly score).
39+
"""
2440
check_is_fitted(self)
2541
return self.best_estimator_.score_samples(X)
2642

2743
@available_if(_estimator_has("predict"))
2844
def predict(self, X):
29-
"""Predict function."""
45+
"""Call predict on the estimator with the best found parameters.
46+
47+
Only available if ``refit=True`` and the underlying estimator supports
48+
``predict``.
49+
50+
Parameters
51+
----------
52+
X : indexable, length n_samples
53+
Must fulfill the input assumptions of the
54+
underlying estimator.
55+
56+
Returns
57+
-------
58+
y_pred : ndarray of shape (n_samples,)
59+
The predicted labels or values for `X` based on the estimator with
60+
the best found parameters.
61+
"""
3062
check_is_fitted(self)
3163
return self.best_estimator_.predict(X)
3264

3365
@available_if(_estimator_has("predict_proba"))
3466
def predict_proba(self, X):
35-
"""Predict Proba function."""
67+
"""Call predict_proba on the estimator with the best found parameters.
68+
69+
Only available if ``refit=True`` and the underlying estimator supports
70+
``predict_proba``.
71+
72+
Parameters
73+
----------
74+
X : indexable, length n_samples
75+
Must fulfill the input assumptions of the
76+
underlying estimator.
77+
78+
Returns
79+
-------
80+
y_pred : ndarray of shape (n_samples,) or (n_samples, n_classes)
81+
Predicted class probabilities for `X` based on the estimator with
82+
the best found parameters. The order of the classes corresponds
83+
to that in the fitted attribute :term:`classes_`.
84+
"""
3685
check_is_fitted(self)
3786
return self.best_estimator_.predict_proba(X)
3887

3988
@available_if(_estimator_has("predict_log_proba"))
4089
def predict_log_proba(self, X):
41-
"""Predict Log Proba function."""
90+
"""Call predict_log_proba on the estimator with the best found parameters.
91+
92+
Only available if ``refit=True`` and the underlying estimator supports
93+
``predict_log_proba``.
94+
95+
Parameters
96+
----------
97+
X : indexable, length n_samples
98+
Must fulfill the input assumptions of the
99+
underlying estimator.
100+
101+
Returns
102+
-------
103+
y_pred : ndarray of shape (n_samples,) or (n_samples, n_classes)
104+
Predicted class log-probabilities for `X` based on the estimator
105+
with the best found parameters. The order of the classes
106+
corresponds to that in the fitted attribute :term:`classes_`.
107+
"""
42108
check_is_fitted(self)
43109
return self.best_estimator_.predict_log_proba(X)
44110

45111
@available_if(_estimator_has("decision_function"))
46112
def decision_function(self, X):
47-
"""Decision Function function."""
113+
"""Call decision_function on the estimator with the best found parameters.
114+
115+
Only available if ``refit=True`` and the underlying estimator supports
116+
``decision_function``.
117+
118+
Parameters
119+
----------
120+
X : indexable, length n_samples
121+
Must fulfill the input assumptions of the
122+
underlying estimator.
123+
124+
Returns
125+
-------
126+
y_score : ndarray of shape (n_samples,) or (n_samples, n_classes) \
127+
or (n_samples, n_classes * (n_classes-1) / 2)
128+
Result of the decision function for `X` based on the estimator with
129+
the best found parameters.
130+
"""
48131
check_is_fitted(self)
49132
return self.best_estimator_.decision_function(X)
50133

51134
@available_if(_estimator_has("transform"))
52135
def transform(self, X):
53-
"""Transform function."""
136+
"""Call transform on the estimator with the best found parameters.
137+
138+
Only available if the underlying estimator supports ``transform`` and
139+
``refit=True``.
140+
141+
Parameters
142+
----------
143+
X : indexable, length n_samples
144+
Must fulfill the input assumptions of the
145+
underlying estimator.
146+
147+
Returns
148+
-------
149+
Xt : {ndarray, sparse matrix} of shape (n_samples, n_features)
150+
`X` transformed in the new space based on the estimator with
151+
the best found parameters.
152+
"""
54153
check_is_fitted(self)
55154
return self.best_estimator_.transform(X)
56155

57156
@available_if(_estimator_has("inverse_transform"))
58157
def inverse_transform(self, X=None, Xt=None):
59-
"""Inverse Transform function."""
158+
"""Call inverse_transform on the estimator with the best found params.
159+
160+
Only available if the underlying estimator implements
161+
``inverse_transform`` and ``refit=True``.
162+
163+
Parameters
164+
----------
165+
X : indexable, length n_samples
166+
Data in the transformed space. Must fulfill the input assumptions
167+
of the underlying estimator.
168+
Xt : array-like of shape (n_samples, n_features), optional
169+
Deprecated in scikit-learn 1.2 and removed in 1.7. Use ``X``
170+
instead. The former parameter name for the transformed data.
171+
172+
Returns
173+
-------
174+
X_original : {ndarray, sparse matrix} of shape (n_samples, n_features)
175+
Result of the `inverse_transform` function for `X` based on the
176+
estimator with the best found parameters.
177+
"""
60178
X = _deprecate_Xt_in_inverse_transform(X, Xt)
61179
check_is_fitted(self)
62180
return self.best_estimator_.inverse_transform(X)

0 commit comments

Comments
 (0)