Skip to content

[WIP] add Accumulated local effects plot - #35055

Open
solegalli wants to merge 7 commits into
scikit-learn:mainfrom
solegalli:accumulated-local-effects
Open

solegalli wants to merge 7 commits into
scikit-learn:mainfrom
solegalli:accumulated-local-effects

Conversation

@solegalli

Copy link
Copy Markdown
Contributor

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:

  • Option 1 would be to just do what the author did.
  • Option 2, not to support discrete variables.

This is still WIP.

@lorentzenchr

Copy link
Copy Markdown
Member
  1. nan
    We could start simple with an error message saying that this is not supported.
  2. Categoricals
    Again, start simple and do not support them.

@solegalli
solegalli force-pushed the accumulated-local-effects branch from b6dab1a to 90bf102 Compare October 28, 2026 14:28
@github-actions

Copy link
Copy Markdown

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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Accumulated local effects (ALE) to inspection

2 participants