You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 2c7d8a1
Browse filesBrowse the repository at this point in the historyBrowse files
authored
Fix TreeExplainer class selection: class_index=0 on binary boosters, out-of-range indices, LightGBM default (#618)
* Fix TreeExplainer class_index=0 for binary gradient boosting classifiers
Binary boosters (sklearn GradientBoosting/HistGradientBoosting, XGBoost,
LightGBM, CatBoost) model a single raw output, the class-1 log-odds. The
converters used class_label only to select per-class trees of multiclass
models, so class_index=0 silently explained class 1.
The converters now negate the leaf values (which already include the base
score / init offset) and empty predictions for class_label=0 of a binary
classifier, which fixes both shapiq backends. Woodelf ignores class_index
for single-output models, so its result is negated as well. A class_index
other than 0, 1 or None now raises a ValueError for these models.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0194yJ4YbD76pieP9CkpnvRv
* Limit the LightGBM binary check to the model header
Searching the whole model string scanned every tree of multiclass models,
whose header has no match (+81 ms on a 10.9 MB model).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0194yJ4YbD76pieP9CkpnvRv
* Move binary class selection into the C tree parsers
The class-0 negation of binary boosters now lives where the parsers already
select the class of multiclass models, instead of in a Python pass over the
converted trees:
- binary_class_sign (converter.hpp) returns the sign selecting class_label
from the single raw output, raising std::invalid_argument (ValueError) for
other labels. The XGBoost, LightGBM and CatBoost parsers apply it to the
leaf values (including base score / bias) while filling them. A model is
binary if it has one output and its serialized objective / loss is binary,
or the caller passes the new optional is_classifier hint (custom
objectives are not serialized as binary).
- sklearn GB/HistGB, which have no C parser, fold the sign into the scaling
and offset they already apply.
- Converted trees carry TreeModel.negated_class_one, so the Woodelf path
reads that flag instead of converting the model a second time.
Conversion speed is unchanged against main.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0194yJ4YbD76pieP9CkpnvRv
* Request class 1 from Woodelf when the trees negate it
Woodelf ignores class_index for single-output models today. Asking for the
class-1 output explicitly and negating it keeps class_index=0 correct if
Woodelf later negates class 0 itself, instead of negating twice.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0194yJ4YbD76pieP9CkpnvRv
* Raise for class indices a tree model does not have
Out-of-range class indices silently explained something else: multiclass
XGBoost and LightGBM models converted to zero trees, and scikit-learn models
read negative indices as counting from the last class. A shared
check_class_label (conversion/common.py, cext/converter.hpp) now raises a
ValueError with the same message everywhere, and convert_tree_model rejects
negative labels, which the C parsers would read as "unspecified".
The LightGBM parser kept the trees of all classes for an unspecified class,
so class_index=None explained the sum of all class margins of a multiclass
model; it now selects class 1, like the other parsers.
A new test checks that the Woodelf backend explains the same class as the
shapiq backend for every valid class_index of every supported family.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0194yJ4YbD76pieP9CkpnvRv
* Update CHANGELOG
---------
Co-authored-by: Maximilian Muschalik <noreply@anthropic.com>
Co-authored-by: Santo Thies <49311372+Advueu963@users.noreply.github.com>
Copy file name to clipboardExpand all lines: CHANGELOG.md
+3-4Lines changed: 3 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,15 +1,14 @@
1
1
# Changelog
2
2
3
-
## Unreleased
3
+
## Development
4
4
5
5
### Bugfix
6
-
6
+
-`TreeExplainer` with `class_index=0` on binary gradient boosting classifiers (scikit-learn `GradientBoostingClassifier` and `HistGradientBoostingClassifier`, `XGBClassifier`, `LGBMClassifier`, `CatBoostClassifier`) silently returned the class-1 explanation in both `mode="pathdependent"` and `mode="interventional"`, including the Woodelf fast path. It now explains the class-0 log-odds, which are the negated class-1 log-odds: the values and the `baseline_value` are the negation of the `class_index=1` explanation. `class_index=None` still explains class 1.
7
+
-`TreeExplainer` with `class_index=None` on a multiclass LightGBM model explained the sum of the raw margins of all classes; it now explains class 1, like for the other libraries.
7
8
- fixes `Game` passing integer or float 0/1 coalition arrays unchanged to `value_function`: games that use the coalitions as masks (e.g. `x[coalition]`, `~coalition`) silently computed wrong values, since integer arrays index positions `0`/`1` and `~` acts bitwise. `Game.__call__` (incl. `verbose=True`), `precompute`, and `compute` now always hand a boolean coalition matrix to `value_function`.
8
-
### Bugfix
9
9
- fixes a bias in the cross-fitted MSR residual adjustment of `ProxySHAP` and `RegressionMSR` (`k_folds > 1`), so the estimates did not converge. Held-out residuals were scaled by `k_folds` and thus also stood in for the coalitions the fold's proxy was trained on.
10
10
Folds are now split within each coalition size (complement pairs kept together), with training coalitions getting a weight of `1` and held-out coalitions a weight depending on how many unseen coalitions of their size exist.
0 commit comments