Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit adc24fd

Browse files
committed
DOC no input validation in constructors
1 parent 68f013a commit adc24fd

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

doc/developers/index.rst

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -647,9 +647,11 @@ To summarize, a `__init__` should look like::
647647
self.param1 = param1
648648
self.param2 = param2
649649

650-
There should be no logic, and the parameters should not be changed.
651-
The corresponding logic should be put where the parameters are used. The
652-
following is wrong::
650+
There should be no logic, not even input validation,
651+
and the parameters should not be changed.
652+
The corresponding logic should be put where the parameters are used,
653+
typically in ``fit``.
654+
The following is wrong::
653655

654656
def __init__(self, param1=1, param2=2, param3=3):
655657
# WRONG: parameters should not be modified
@@ -660,8 +662,9 @@ following is wrong::
660662
# the argument in the constructor
661663
self.param3 = param2
662664

663-
Scikit-learn relies on this mechanism to introspect objects to set
664-
their parameters by cross-validation.
665+
The reason for postponing the validation is that the same validation
666+
would have to be performed in ``set_params``,
667+
which is used in algorithms like ``GridSearchCV``.
665668

666669
Fitting
667670
^^^^^^^

0 commit comments

Comments
 (0)