Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
scikit-learn
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ian Johnson
scikit-learn
Commits
8a586e51
Commit
8a586e51
authored
13 years ago
by
Gael Varoquaux
Browse files
Options
Downloads
Patches
Plain Diff
DOC: explicit the __init__ convention
parent
badce0cc
Branches
main
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
doc/developers/index.rst
+22
-1
22 additions, 1 deletion
doc/developers/index.rst
with
22 additions
and
1 deletion
doc/developers/index.rst
+
22
−
1
View file @
8a586e51
...
...
@@ -349,6 +349,7 @@ data-independent parameters (overriding previous parameter values passed
to ``__init__``). This method is not required for an object to be an
estimator.
All estimators should inherit from ``scikit.learn.base.BaseEstimator``.
Instantiation
^^^^^^^^^^^^^
...
...
@@ -377,7 +378,27 @@ correspond to an attribute on the instance**. The scikit relies on this
to find what are the relevent attributes to set on an estimator when
doing model selection.
All estimators should inherit from ``scikit.learn.base.BaseEstimator``.
To summarize, a `__init__` should look like::
def __init__(self, param1=1, param2=2):
self.param1 = param1
self.param2 = param2
There should be no logic, and the parameters should not be changed.
The corresponding logic should be put when the parameters are used. The
following is wrong::
def __init__(self, param1=1, param2=2, param3=3):
# WRONG: parameters should not be modified
if param1 > 1:
param2 += 1
self.param1 = param1
# WRONG: the object's attributes should have exactly the name of
# the argument in the constructor
self.param3 = param2
The scikit-learn relies on this mechanism to introspect object to set
their parameters by cross-validation.
Fitting
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment