Skip to content

Commit cee1a3c

Browse files
inherit docstrings from sklearn (#2420)
1 parent 7add6a5 commit cee1a3c

File tree

2 files changed

+7
-98
lines changed

2 files changed

+7
-98
lines changed

sklearnex/neighbors/_lof.py

Lines changed: 3 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# ===============================================================================
1616

1717
import warnings
18+
from functools import wraps
1819

1920
import numpy as np
2021
from sklearn.neighbors import LocalOutlierFactor as _sklearn_LocalOutlierFactor
@@ -142,28 +143,9 @@ def _predict(self, X=None):
142143
# This would cause issues in fit_predict. Also, available_if
143144
# is hard to unwrap, and this is the most straighforward way.
144145
@available_if(_sklearn_LocalOutlierFactor._check_novelty_fit_predict)
146+
@wraps(_sklearn_LocalOutlierFactor.fit_predict, assigned=["__doc__"])
145147
@wrap_output_data
146148
def fit_predict(self, X, y=None):
147-
"""Fit the model to the training set X and return the labels.
148-
149-
**Not available for novelty detection (when novelty is set to True).**
150-
Label is 1 for an inlier and -1 for an outlier according to the LOF
151-
score and the contamination parameter.
152-
153-
Parameters
154-
----------
155-
X : {array-like, sparse matrix} of shape (n_samples, n_features), default=None
156-
The query sample or samples to compute the Local Outlier Factor
157-
w.r.t. the training samples.
158-
159-
y : Ignored
160-
Not used, present for API consistency by convention.
161-
162-
Returns
163-
-------
164-
is_inlier : ndarray of shape (n_samples,)
165-
Returns -1 for anomalies/outliers and 1 for inliers.
166-
"""
167149
return self.fit(X)._predict()
168150

169151
def _kneighbors(self, X=None, n_neighbors=None, return_distance=True):
@@ -185,34 +167,9 @@ def _kneighbors(self, X=None, n_neighbors=None, return_distance=True):
185167
kneighbors = wrap_output_data(_kneighbors)
186168

187169
@available_if(_sklearn_LocalOutlierFactor._check_novelty_score_samples)
170+
@wraps(_sklearn_LocalOutlierFactor.score_samples, assigned=["__doc__"])
188171
@wrap_output_data
189172
def score_samples(self, X):
190-
"""Opposite of the Local Outlier Factor of X.
191-
192-
It is the opposite as bigger is better, i.e. large values correspond
193-
to inliers.
194-
195-
**Only available for novelty detection (when novelty is set to True).**
196-
The argument X is supposed to contain *new data*: if X contains a
197-
point from training, it considers the later in its own neighborhood.
198-
Also, the samples in X are not considered in the neighborhood of any
199-
point. Because of this, the scores obtained via ``score_samples`` may
200-
differ from the standard LOF scores.
201-
The standard LOF scores for the training data is available via the
202-
``negative_outlier_factor_`` attribute.
203-
204-
Parameters
205-
----------
206-
X : {array-like, sparse matrix} of shape (n_samples, n_features)
207-
The query sample or samples to compute the Local Outlier Factor
208-
w.r.t. the training samples.
209-
210-
Returns
211-
-------
212-
opposite_lof_scores : ndarray of shape (n_samples,)
213-
The opposite of the Local Outlier Factor of each input samples.
214-
The lower, the more abnormal.
215-
"""
216173
check_is_fitted(self)
217174

218175
distances_X, neighbors_indices_X = self._kneighbors(

sklearnex/svm/nusvc.py

Lines changed: 4 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
# limitations under the License.
1515
# ==============================================================================
1616

17+
from functools import wraps
18+
1719
import numpy as np
1820
from sklearn.exceptions import NotFittedError
1921
from sklearn.metrics import accuracy_score
@@ -139,64 +141,14 @@ def score(self, X, y, sample_weight=None):
139141
)
140142

141143
@available_if(_sklearn_NuSVC._check_proba)
144+
@wraps(_sklearn_NuSVC.predict_proba, assigned=["__doc__"])
142145
def predict_proba(self, X):
143-
"""
144-
Compute probabilities of possible outcomes for samples in X.
145-
146-
The model need to have probability information computed at training
147-
time: fit with attribute `probability` set to True.
148-
149-
Parameters
150-
----------
151-
X : array-like of shape (n_samples, n_features)
152-
For kernel="precomputed", the expected shape of X is
153-
(n_samples_test, n_samples_train).
154-
155-
Returns
156-
-------
157-
T : ndarray of shape (n_samples, n_classes)
158-
Returns the probability of the sample for each class in
159-
the model. The columns correspond to the classes in sorted
160-
order, as they appear in the attribute :term:`classes_`.
161-
162-
Notes
163-
-----
164-
The probability model is created using cross validation, so
165-
the results can be slightly different than those obtained by
166-
predict. Also, it will produce meaningless results on very small
167-
datasets.
168-
"""
169146
check_is_fitted(self)
170147
return self._predict_proba(X)
171148

172149
@available_if(_sklearn_NuSVC._check_proba)
150+
@wraps(_sklearn_NuSVC.predict_log_proba, assigned=["__doc__"])
173151
def predict_log_proba(self, X):
174-
"""Compute log probabilities of possible outcomes for samples in X.
175-
176-
The model need to have probability information computed at training
177-
time: fit with attribute `probability` set to True.
178-
179-
Parameters
180-
----------
181-
X : array-like of shape (n_samples, n_features) or \
182-
(n_samples_test, n_samples_train)
183-
For kernel="precomputed", the expected shape of X is
184-
(n_samples_test, n_samples_train).
185-
186-
Returns
187-
-------
188-
T : ndarray of shape (n_samples, n_classes)
189-
Returns the log-probabilities of the sample for each class in
190-
the model. The columns correspond to the classes in sorted
191-
order, as they appear in the attribute :term:`classes_`.
192-
193-
Notes
194-
-----
195-
The probability model is created using cross validation, so
196-
the results can be slightly different than those obtained by
197-
predict. Also, it will produce meaningless results on very small
198-
datasets.
199-
"""
200152
xp, _ = get_namespace(X)
201153

202154
return xp.log(self.predict_proba(X))

0 commit comments

Comments
 (0)