ENH Support sample weights in partial_dependence - #25209
Conversation
glemaitre
left a comment
There was a problem hiding this comment.
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 <[email protected]>
Co-authored-by: Guillaume Lemaitre <[email protected]>
Co-authored-by: Guillaume Lemaitre <[email protected]>
Co-authored-by: Guillaume Lemaitre <[email protected]>
Co-authored-by: Guillaume Lemaitre <[email protected]>
Co-authored-by: Guillaume Lemaitre <[email protected]>
|
@vitaliset Could you try to get CI green again? This might help attract a 2nd reviewer. |
vitaliset
left a comment
There was a problem hiding this comment.
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 <[email protected]>
Co-authored-by: Christian Lorentzen <[email protected]>
glemaitre
left a comment
There was a problem hiding this comment.
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 ? |
lorentzenchr
left a comment
There was a problem hiding this comment.
LGTM
As a follow up, we should propagate sample weight support to PartialDependenceDisplay.from_stimator.
Co-authored-by: Christian Lorentzen <[email protected]>
|
@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_weightin 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_weightif someone wishes to use it (for instance, when you know yourXdoes 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_weightas it is calculating the average over the training data of the estimator (which can consider the trainingsample_weightfor 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