Repository navigation
Conversation
Member
|
solegalli
force-pushed
the
accumulated-local-effects
branch
from
October 28, 2026 14:28
b6dab1a to
90bf102
Compare
|
This PR exceeds the recommended size of 500 lines changed. Consider splitting it into smaller PRs to ease the review process. Please make sure you read our Contributing guide and in particular our Pull Request guidelines |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reference Issues/PRs
Fixes #30223.
What does this implement/fix? Explain your changes.
The PR adds a new function to calculate accumulated local effects based on Apley and Zhu 2019:
Also discussed in https://christophm.github.io/interpretable-ml-book/ale.html
Introduce yourself
I am Sole, data scientist and Python dev. I met some of developers recently at Euroscipy 2026.
I teach a course on interpretable machine learning, and while updating the course, I noticed that libraries that support ALE are either not being updated, or not fast enough, so given that sklearn already supports PDP and ICE, it felt natural that it should also support ALE, which is an alternative calculation of how feature value changes affect the model prediction.
AI usage disclosure
I use Claude Opus 5.5 to start off and then I review every line.
Any other comments?
While creating the first draft I came across some issues that need resolving.
NAN values. The problem arises when models support nan values, like tree based models, because it is not clear which values should be used to replace those nan.
Briefly, ale sorts values into intervals. Then replaces each sample value with the interval edges (2 replacements), it obtains the predictions, and the local effect is the prediction at the maximum value minus the prediction at the minimum value. Pretty much like PDP, but PDP replaces all samples with the same value. Here, we'd replace each sample with 2 values only, min edge and max edge.
The problem with nan is, that it's not clear which value should be used for replacement, because it can't fall into any bin. So my first suggestion would be to exclude nan from the calculation, even if they can be used by the model.
The second problem (not a big one) is how to handle categorical variables. The original paper and molnar's book suggests a way in which to assign order to the categories based on feature proximity. I'd say that's out of scope and we outsource that problem to the user.
discrete/categorical variables: The next question is, how do we calculate the effects for discrete/categorical variables. The paper does not describe it clearly, but the R implementation does. This is what basically took most of my time to understand, because, no matter how long I think about it, it doesn't make a lot of sense in my head.
We have 2 options here:
This is still WIP.