Skip to content

Commit 8fef1d6

Browse files
committed
Add docstrings for best_estimator.py
1 parent f1ba357 commit 8fef1d6

1 file changed

Lines changed: 123 additions & 7 deletions

File tree

src/hyperactive/integrations/sklearn/best_estimator.py

Lines changed: 123 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,43 +20,159 @@ 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+
.. versionadded:: 0.24
29+
30+
Parameters
31+
----------
32+
X : iterable
33+
Data to predict on. Must fulfill input requirements
34+
of the underlying estimator.
35+
36+
Returns
37+
-------
38+
y_score : ndarray of shape (n_samples,)
39+
The ``best_estimator_.score_samples`` method.
40+
"""
2441
check_is_fitted(self)
2542
return self.best_estimator_.score_samples(X)
2643

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

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

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

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

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

57157
@available_if(_estimator_has("inverse_transform"))
58158
def inverse_transform(self, X=None, Xt=None):
59-
"""Inverse Transform function."""
159+
"""Call inverse_transform on the estimator with the best found params.
160+
161+
Only available if the underlying estimator implements
162+
``inverse_transform`` and ``refit=True``.
163+
164+
Parameters
165+
----------
166+
X : indexable, length n_samples
167+
Must fulfill the input assumptions of the
168+
underlying estimator.
169+
170+
Returns
171+
-------
172+
X_original : {ndarray, sparse matrix} of shape (n_samples, n_features)
173+
Result of the `inverse_transform` function for `X` based on the
174+
estimator with the best found parameters.
175+
"""
60176
X = _deprecate_Xt_in_inverse_transform(X, Xt)
61177
check_is_fitted(self)
62178
return self.best_estimator_.inverse_transform(X)

0 commit comments

Comments
 (0)