10000 Added comment about optional ``y`` in the developer docs. · scikit-learn/scikit-learn@f91dee7 · GitHub
[go: up one dir, main page]

Skip to content

Commit f91dee7

Browse files
committed
Added comment about optional y in the developer docs.
1 parent 6632043 commit f91dee7

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

doc/developers/index.rst

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -716,8 +716,11 @@ is not met, an exception of type ``ValueError`` should be raised.
716716
``y`` might be ignored in the case of unsupervised learning. However, to
717717
make it possible to use the estimator as part of a pipeline that can
718718
mix both supervised and unsupervised transformers, even unsupervised
719-
estimators are kindly asked to accept a ``y=None`` keyword argument in
719+
estimators need to accept a ``y=None`` keyword argument in
720720
the second position that is just ignored by the estimator.
721+
For the same reason, ``fit_predict``, ``fit_transform``, ``score``,
722+
``transform`` and ``partial_fit`` methods need to accept a ``y`` argument in
723+
the second place if they are implemented.
721724

722725
The method should return the object (``self``). This pattern is useful
723726
to be able to implement quick one liners in an IPython session such as::
@@ -857,9 +860,10 @@ last step, it needs to provide a ``fit`` or ``fit_transform`` function.
857860
To be able to evaluate the pipeline on any data but the training set,
858861
it also needs to provide a ``transform`` function.
859862
There are no special requirements for the last step in a pipeline, except that
860-
it has a ``fit`` function. All ``fit`` and ``fit_transform`` functions must
861-
take arguments ``X, y``, even if y is not used.
862-
863+
it has a ``fit`` function. All ``fit`` and ``fit_transform`` functions must
864+
take arguments ``X, y``, even if y is not used. Similarly, for ``score`` to be
865+
usable, the last step of the pipeline needs to have a ``score`` function that
866+
accepts an optional ``y``.
863867

864868
Working notes
865869
-------------

sklearn/cluster/k_means_.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ def fit(self, X, y=None):
795795
n_jobs=self.n_jobs)
796796
return self
797797

798-
def fit_predict(self, X):
798+
def fit_predict(self, X, y=None):
799799
"""Compute cluster centers and predict cluster index for each sample.
800800
801801
Convenience method; equivalent to calling fit(X) followed by

sklearn/utils/estimator_checks.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ def set_fast_parameters(estimator):
8181
# K-Means
8282
estimator.set_params(n_init=2)
8383

84+
if estimator.__class__.__name__ == "SelectFdr":
85+
# avoid not selecting any features
86+
estimator.set_params(alpha=.5)
87+
8488
if isinstance(estimator, BaseRandomProjection):
8589
# Due to the jl lemma and often very few samples, the number
8690
# of components of the random matrix projection will be probably
@@ -253,7 +257,7 @@ def check_fit_score_takes_y(name, Estimator):
253257
estimator = Estimator()
254258
set_fast_parameters(estimator)
255259
set_random_state(estimator)
256-
funcs = ["fit", "score", "partial_fit"]
260+
funcs = ["fit", "score", "partial_fit", "fit_predict", "fit_transform"]
257261

258262
for func_name in funcs:
259263
func = getattr(estimator, func_name, None)

0 commit comments

Comments
 (0)
0