Skip to content

Tree refactor#501

Merged
mmschlk merged 61 commits intomainfrom
tree_refactor
Mar 13, 2026
Merged

Tree refactor#501
mmschlk merged 61 commits intomainfrom
tree_refactor

Conversation

@Advueu963
Copy link
Copy Markdown
Collaborator

@Advueu963 Advueu963 commented Mar 13, 2026

Motivation and Context

The shapiq.tree module had grown organically into a single-file/flat layout that was increasingly hard to extend. This PR does three things simultaneously:

  1. Refactors shapiq.tree into a clean subpackage — separating conversion logic, explanation algorithms, validation, and the new algorithms into dedicated submodules. This makes the codebase easier to maintain, test, and
    extend.
  2. Adds ProxySHAP — a new approximator that uses a lightweight proxy tree model (XGBoost by default) to compute interactions cheaply and then corrects for the approximation error on the true model. This is particularly
    useful when the true model is expensive to query.
  3. Adds LinearTreeSHAP — an efficient first-order-only Shapley value implementation based on the Yu et al. (2022) NeurIPS paper, backed by a dedicated C++ extension for high throughput.

Along the way, InterventionalGame gains multi-class LightGBM support (a correctness fix), IsolationForest is added to the list of supported sklearn tree models, and InterventionalTreeExplainer is ported to use batched
sparse C-extensions for faster tree traversal.


Public API Changes

  • No Public API changes
  • Yes, Public API changes (Details below)

New exports:

  • shapiq.approximator.ProxySHAP — proxy-model-accelerated interaction estimator
  • shapiq.approximator.MSRBiased — biased multilinear-extension sampling regression (also used internally by ProxySHAP)
  • shapiq.tree.LinearTreeSHAP — fast first-order Shapley values for tree models (index="SV" only)
  • shapiq.tree.InterventionalTreeExplainer — previously internal, now a first-class export
  • shapiq.tree.InterventionalGame — previously internal, now a first-class export

Unchanged interfaces:

  • shapiq.TreeExplainer — public interface is fully preserved; the refactor is internal only.

New model support:

  • sklearn.ensemble.IsolationForest is now accepted by TreeExplainer and validate_tree_model.

How Has This Been Tested?

  • Unit tests cover ProxySHAP, MSRBiased, and LinearTreeSHAP for correctness of outputs and supported index types.
  • The InterventionalGame LightGBM multi-class fix is tested with a multi-class LGBMClassifier.
  • The refactored shapiq.tree subpackage is tested end-to-end via the existing TreeExplainer test suite, which exercises all supported model types (sklearn trees, XGBoost, LightGBM) and interaction indices.
  • IsolationForest support is covered by a dedicated test.
  • All tests run locally via uv run pytest tests/shapiq.

Checklist

  • The changes have been tested locally.
  • Documentation has been updated (if the public API or usage changes).
  • An entry has been added to CHANGELOG.md (if relevant for users).
  • The code follows the project's style guidelines.
  • I have considered the impact of these changes on the public API.

Advueu963 and others added 30 commits March 9, 2026 16:13
Signed-off-by: Maximilian <maximilian.muschalik@gmail.com>
Signed-off-by: Maximilian <maximilian.muschalik@gmail.com>
Signed-off-by: Maximilian <maximilian.muschalik@gmail.com>
Signed-off-by: Maximilian <maximilian.muschalik@gmail.com>
Signed-off-by: Maximilian <maximilian.muschalik@gmail.com>
@mmschlk mmschlk self-requested a review March 13, 2026 15:31
Copy link
Copy Markdown
Owner

@mmschlk mmschlk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many changes which we tested quite strongly. I am still expecting some issues we need to find before release.

@mmschlk mmschlk merged commit 56097a7 into main Mar 13, 2026
10 checks passed
@mmschlk mmschlk deleted the tree_refactor branch March 13, 2026 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

2 participants