Skip to content

Commit 813d7de

Browse files
NicolasHugjnothman
authored andcommitted
DOC Added docstring checks for feature_selection, kernel_approximation and neighbors modules (scikit-learn#11421)
1 parent 6c0e9b4 commit 813d7de

File tree

6 files changed

+107
-15
lines changed

6 files changed

+107
-15
lines changed

sklearn/feature_selection/rfe.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,16 +262,61 @@ def _get_support_mask(self):
262262

263263
@if_delegate_has_method(delegate='estimator')
264264
def decision_function(self, X):
265+
"""Compute the decision function of ``X``.
266+
267+
Parameters
268+
----------
269+
X : array-like or sparse matrix, shape = [n_samples, n_features]
270+
The input samples. Internally, it will be converted to
271+
``dtype=np.float32`` and if a sparse matrix is provided
272+
to a sparse ``csr_matrix``.
273+
274+
Returns
275+
-------
276+
score : array, shape = [n_samples, n_classes] or [n_samples]
277+
The decision function of the input samples. The order of the
278+
classes corresponds to that in the attribute `classes_`.
279+
Regression and binary classification produce an array of shape
280+
[n_samples].
281+
"""
265282
check_is_fitted(self, 'estimator_')
266283
return self.estimator_.decision_function(self.transform(X))
267284

268285
@if_delegate_has_method(delegate='estimator')
269286
def predict_proba(self, X):
287+
"""Predict class probabilities for X.
288+
289+
Parameters
290+
----------
291+
X : array-like or sparse matrix, shape = [n_samples, n_features]
292+
The input samples. Internally, it will be converted to
293+
``dtype=np.float32`` and if a sparse matrix is provided
294+
to a sparse ``csr_matrix``.
295+
296+
Returns
297+
-------
298+
p : array of shape = [n_samples, n_classes]
299+
The class probabilities of the input samples. The order of the
300+
classes corresponds to that in the attribute `classes_`.
301+
"""
270302
check_is_fitted(self, 'estimator_')
271303
return self.estimator_.predict_proba(self.transform(X))
272304

273305
@if_delegate_has_method(delegate='estimator')
274306
def predict_log_proba(self, X):
307+
"""Predict class log-probabilities for X.
308+
309+
Parameters
310+
----------
311+
X : array of shape [n_samples, n_features]
312+
The input samples.
313+
314+
Returns
315+
-------
316+
p : array of shape = [n_samples, n_classes]
317+
The class log-probabilities of the input samples. The order of the
318+
classes corresponds to that in the attribute `classes_`.
319+
"""
275320
check_is_fitted(self, 'estimator_')
276321
return self.estimator_.predict_log_proba(self.transform(X))
277322

sklearn/feature_selection/univariate_selection.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ def f_oneway(*args):
5050
5151
Parameters
5252
----------
53-
sample1, sample2, ... : array_like, sparse matrices
54-
The sample measurements should be given as arguments.
53+
*args : array_like, sparse matrices
54+
sample1, sample2... The sample measurements should be given as
55+
arguments.
5556
5657
Returns
5758
-------

sklearn/kernel_approximation.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,19 @@ def __init__(self, sample_steps=2, sample_interval=None):
302302
self.sample_interval = sample_interval
303303

304304
def fit(self, X, y=None):
305-
"""Set parameters."""
305+
"""Set the parameters
306+
307+
Parameters
308+
----------
309+
X : array-like, shape (n_samples, n_features)
310+
Training data, where n_samples in the number of samples
311+
and n_features is the number of features.
312+
313+
Returns
314+
-------
315+
self : object
316+
Returns the transformer.
317+
"""
306318
X = check_array(X, accept_sparse='csr')
307319
if self.sample_interval is None:
308320
# See reference, figure 2 c)
@@ -420,27 +432,27 @@ class Nystroem(BaseEstimator, TransformerMixin):
420432
and the keyword arguments passed to this object as kernel_params, and
421433
should return a floating point number.
422434
423-
n_components : int
424-
Number of features to construct.
425-
How many data points will be used to construct the mapping.
426-
427435
gamma : float, default=None
428436
Gamma parameter for the RBF, laplacian, polynomial, exponential chi2
429437
and sigmoid kernels. Interpretation of the default value is left to
430438
the kernel; see the documentation for sklearn.metrics.pairwise.
431439
Ignored by other kernels.
432440
433-
degree : float, default=None
434-
Degree of the polynomial kernel. Ignored by other kernels.
435-
436441
coef0 : float, default=None
437442
Zero coefficient for polynomial and sigmoid kernels.
438443
Ignored by other kernels.
439444
445+
degree : float, default=None
446+
Degree of the polynomial kernel. Ignored by other kernels.
447+
440448
kernel_params : mapping of string to any, optional
441449
Additional parameters (keyword arguments) for kernel function passed
442450
as callable object.
443451
452+
n_components : int
453+
Number of features to construct.
454+
How many data points will be used to construct the mapping.
455+
444456
random_state : int, RandomState instance or None, optional (default=None)
445457
If int, random_state is the seed used by the random number generator;
446458
If RandomState instance, random_state is the random number generator;

sklearn/neighbors/approximate.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,53 @@ def _to_hash(projected):
8282
return out.reshape(projected.shape[0], -1)
8383

8484
def fit_transform(self, X, y=None):
85+
"""
86+
Parameters
87+
----------
88+
X : array-like, shape = [n_samples, n_features]
89+
Training vectors, where n_samples is the number of samples and
90+
n_features is the number of predictors.
91+
"""
92+
8593
self.fit(X)
8694
return self.transform(X)
8795

8896
def transform(self, X):
97+
"""
98+
Parameters
99+
----------
100+
X : array-like, shape = [n_samples, n_features]
101+
Training vectors, where n_samples is the number of samples and
102+
n_features is the number of predictors.
103+
"""
89104
return self._to_hash(super(ProjectionToHashMixin, self).transform(X))
90105

91106

92107
class GaussianRandomProjectionHash(ProjectionToHashMixin,
93108
GaussianRandomProjection):
94-
"""Use GaussianRandomProjection to produce a cosine LSH fingerprint"""
109+
"""Use GaussianRandomProjection to produce a cosine LSH fingerprint
110+
111+
Parameters
112+
----------
113+
114+
n_components : int or 'auto', optional (default = 32)
115+
Dimensionality of the target projection space.
116+
117+
n_components can be automatically adjusted according to the
118+
number of samples in the dataset and the bound given by the
119+
Johnson-Lindenstrauss lemma. In that case the quality of the
120+
embedding is controlled by the ``eps`` parameter.
121+
122+
It should be noted that Johnson-Lindenstrauss lemma can yield
123+
very conservative estimated of the required number of components
124+
as it makes no assumption on the structure of the dataset.
125+
126+
random_state : int, RandomState instance or None, optional (default=None)
127+
If int, random_state is the seed used by the random number generator;
128+
If RandomState instance, random_state is the random number generator;
129+
If None, the random number generator is the RandomState instance used
130+
by `np.random`.
131+
"""
95132
def __init__(self,
96133
n_components=32,
97134
random_state=None):

sklearn/neighbors/kde.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def fit(self, X, y=None, sample_weight=None):
121121
X : array_like, shape (n_samples, n_features)
122122
List of n_features-dimensional data points. Each row
123123
corresponds to a single data point.
124-
sample_weight: array_like, shape (n_samples,), optional
124+
sample_weight : array_like, shape (n_samples,), optional
125125
List of sample weights attached to the data X.
126126
"""
127127
algorithm = self._choose_algorithm(self.algorithm, self.metric)

sklearn/tests/test_docstring_parameters.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,10 @@
2727
IGNORED_MODULES = (
2828
'cluster',
2929
'datasets',
30-
'feature_selection',
31-
'kernel_approximation',
3230
'model_selection',
3331
'multioutput',
3432
'setup',
3533
'utils',
36-
'neighbors',
3734
# Deprecated modules
3835
'cross_validation',
3936
'grid_search',

0 commit comments

Comments
 (0)