-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
ENH Support sample weights in partial_dependence #25209
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
Conversation
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.
Here is a first pass of review for this feature. We will have to open another PR to add support for sample_weight
in the PartialDependenceDisplay
@vitaliset Would you have time to address the review comments? |
Hello @glemaitre! I'll do it on this weekend! Thanks for the detailed review! |
Co-authored-by: Guillaume Lemaitre <g.lemaitre58@gmail.com>
Co-authored-by: Guillaume Lemaitre <g.lemaitre58@gmail.com>
Co-authored-by: Guillaume Lemaitre <g.lemaitre58@gmail.com>
Co-authored-by: Guillaume Lemaitre <g.lemaitre58@gmail.com>
Co-authored-by: Guillaume Lemaitre <g.lemaitre58@gmail.com>
Co-authored-by: Guillaume Lemaitre <g.lemaitre58@gmail.com>
@vitaliset Could you try to get CI green again? This might help attract a 2nd reviewer. |
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.
Thank you for the advice @lorentzenchr. I hadn't realized it was not green.
It seems to be just the "values" deprecation (the resolved conflict from my last commit). :)
Co-authored-by: Christian Lorentzen <lorentzen.ch@gmail.com>
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.
Putting back my +1 here.
Co-authored-by: Christian Lorentzen <lorentzen.ch@gmail.com>
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.
Since my review, we added the parameter validation for this function. You need to validate sample_weight
as an array-like or None
to avoid the remaining failure.
There are already 2 reviewers here so I just made a quick pass. Everything looks good. @lorentzenchr are you happy with the current state of the PR ? |
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.
LGTM
As a follow up, we should propagate sample weight support to PartialDependenceDisplay.from_stimator
.
Co-authored-by: Christian Lorentzen <lorentzen.ch@gmail.com>
@vitaliset CI is green. Can I merge? |
Sure @lorentzenchr! By the way, I'll be working on |
This is my first non-trivial merged PR to scikit-learn! 🥳 I am extremely grateful for the insightful comments provided by @glemaitre, @lorentzenchr, @jeremiedbb, and @NicolasHug during both review and issue discussions. Also, I would like to express my appreciation to @mayer79 for initiating the issue and allowing me the opportunity to work on it. Thank you so much folks! |
Reference Issues/PRs
Towards #24872. Once this PR is merged I will open another PR to add support for
sample_weight
in thePartialDependenceDisplay
, as glemaitre pointed out during review.As partial dependence of a model at a point is defined as an expectation, as #24872 points out, it should respect
sample_weight
if someone wishes to use it (for instance, when you know yourX
does not follow the distribution you are interested in).Note: as discussed in #24872 (comment), the
method='recursion'
should not be able to usepartial_dependence
'ssample_weight
as it is calculating the average over the training data of the estimator (which can consider the trainingsample_weight
for some types of algorithms as discussed on the original issue #24872 (comment)). This PR changes the calculation of themethod='brute'
.Thanks in advance for the reviews! :D