Repository navigation
Fix RegressionTree diagram labels truncating fractional E[Y] values - #712
Open
Jefferyjia wants to merge 1 commit into
Open
Jefferyjia wants to merge 1 commit into
Jefferyjia wants to merge 1 commit into
Conversation
In _graph_from_tree, both the leaf and split branches cast tree_.value to int. For classifiers this matches the "# Obs" label, but for regression tree_.value holds the per-node mean of the target, so map(int) truncated it toward zero: leaves predicting -0.5/1.5 were labeled "E[Y]: 0" / "E[Y]: 1" in explain_global/explain_local diagrams, while predictions themselves were correct. Branch the cast on _is_classifier: classifiers keep the integer cast (byte-for-byte identical display), regression trees cast to float so the E[Y] labels show the actual node means. Adds regression tests asserting the exact E[Y] labels for RegressionTree and the unchanged integer "# Obs" formatting for ClassificationTree. Fixes interpretml#711 Signed-off-by: Jefferyjia <18818263299@163.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #712 +/- ##
==========================================
- Coverage 67.83% 67.77% -0.07%
==========================================
Files 77 77
Lines 11893 11894 +1
==========================================
- Hits 8068 8061 -7
- Misses 3825 3833 +8 Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Problem
RegressionTreeleaves can predict fractional values, but the tree diagrams inexplain_global()/explain_local()show integer-truncatedE[Y]labels.Minimal repro (InterpretML 0.7.8, Python 3.12, scikit-learn 1.9.1):
Root cause
In
_graph_from_tree(python/interpret-core/interpret/glassbox/_decisiontree.py), both the leaf and the split branch buildvaluewith:For a classifier
tree_.value[i]holds (weighted) sample counts, so the integer cast matches the# Obs: ...label. For regression, the same array holds the per-node mean of the target (E[Y]), andmap(int, ...)truncates it toward zero. The prediction path is untouched — only the diagram labels are wrong.Fix
Branch the cast on
_is_classifier(self):map(int, ...)— display byte-for-byte identical to beforefloat, soE[Y]labels show the actual node meansValidation
test_regression_tree_labelsasserts the exactE[Y]: 0.5 / -0.5 / 1.5labels in bothexplain_global()andexplain_local()— fails onmain(truncated0/1), passes with this fix.test_classification_tree_labelsasserts the classifier diagram keeps integer# Obs: ...formatting.test_decisiontree.pysuite: 107 passed, 18 skipped (pre-existing sklearn estimator-check skips).ruff format --checkclean on both changed files.Fixes #711
Transparency note: this analysis was prepared with the help of Claude (AI); I have reviewed the code and verified the reproduction myself.