-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
ENH default routing policy for sample weight #30887
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
import re | ||
import warnings | ||
from collections import defaultdict | ||
from typing import Union | ||
|
||
import numpy as np | ||
|
||
|
@@ -153,7 +154,20 @@ def _clone_parametrized(estimator, *, safe=True): | |
return new_object | ||
|
||
|
||
class BaseEstimator(_HTMLDocumentationLinkMixin, _MetadataRequester): | ||
class _SampleWeightEstimatorMixin(_MetadataRequester): | ||
"""A Mixin to request ``sample_weight`` by default. | ||
|
||
This Mixin makes the object to request ``sample_weight`` by default as ``True`` | ||
for both ``fit`` and ``score`` methods. | ||
|
||
.. versionadded:: 1.7 | ||
""" | ||
|
||
__metadata_request__fit: dict[str, Union[bool, str]] = {"sample_weight": True} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IIUC, I don't think we want to have a constant default routing w/o user input. By that, I mean we want to have a "default routing" setting which is enabled with a global config. Something along the lines of sklearn.set_config(enable_metadata_routing="default_routing") And that would enable a default routing kinda thing. Also, the default routing seems to me that it should be on the instance level and not the class level. I remember cases where routing would depend on constructor arguments (sub-estimator specifically). It could be something along the lines of: class MyEstimator(...):
def __sklearn_default_routing__(self):
return {"fit": {"sample_weight": True}} We need to build that in the routing machinery, and then enable that for our estimators. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the point of having a default routing for sample weight is that it's enabled by default (similarly to what we do for the CV groups). |
||
__metadata_request__score: dict[str, Union[bool, str]] = {"sample_weight": True} | ||
|
||
|
||
class BaseEstimator(_HTMLDocumentationLinkMixin, _SampleWeightEstimatorMixin): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should apply to the estimators individually, and not |
||
"""Base class for all estimators in scikit-learn. | ||
|
||
Inheriting from this class provides default implementations of: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we probably want to have two mixins, for
fit
andscore
.