Skip to content

Fix RegressionTree diagram labels truncating fractional E[Y] values - #712

Open
Jefferyjia wants to merge 1 commit into
interpretml:mainfrom
Jefferyjia:fix-regression-tree-ey-labels
Open

Jefferyjia wants to merge 1 commit into
interpretml:mainfrom
Jefferyjia:fix-regression-tree-ey-labels

Conversation

@Jefferyjia

Copy link
Copy Markdown

Problem

RegressionTree leaves can predict fractional values, but the tree diagrams in explain_global() / explain_local() show integer-truncated E[Y] labels.

Minimal repro (InterpretML 0.7.8, Python 3.12, scikit-learn 1.9.1):

import numpy as np
from interpret.glassbox import RegressionTree

X = np.array([[0.0], [1.0]])
model = RegressionTree(max_depth=1).fit(X, [-0.5, 1.5])
print(model.predict(X).tolist())                    # [-0.5, 1.5]
print(model.explain_global().data(None)["nodes"][1]["data"]["label"])  # E[Y]: 0
prediction [-0.5, 1.5]
global [0.0, 0.0, 1.0]   # diagram labels, expected [0.5, -0.5, 1.5]
local  [0.0, 0.0, 1.0]

Root cause

In _graph_from_tree (python/interpret-core/interpret/glassbox/_decisiontree.py), both the leaf and the split branch build value with:

value = [list(map(int, x)) for x in tree_.value[i].tolist()]

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]), and map(int, ...) truncates it toward zero. The prediction path is untouched — only the diagram labels are wrong.

Fix

Branch the cast on _is_classifier(self):

  • classifier path keeps map(int, ...) — display byte-for-byte identical to before
  • regression path casts to float, so E[Y] labels show the actual node means

Validation

  • New test_regression_tree_labels asserts the exact E[Y]: 0.5 / -0.5 / 1.5 labels in both explain_global() and explain_local() — fails on main (truncated 0 / 1), passes with this fix.
  • New test_classification_tree_labels asserts the classifier diagram keeps integer # Obs: ... formatting.
  • Full test_decisiontree.py suite: 107 passed, 18 skipped (pre-existing sklearn estimator-check skips).
  • ruff format --check clean 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.

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

codecov Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 67.77%. Comparing base (003136e) to head (08a77b5).

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     
Flag Coverage Δ
bdist_linux_311_python 67.52% <100.00%> (-0.02%) ⬇️
bdist_linux_312_python ?
bdist_linux_313_python ?
bdist_linux_314_python 67.45% <100.00%> (+<0.01%) ⬆️
bdist_linuxarm_311_python 67.56% <100.00%> (+<0.01%) ⬆️
bdist_linuxarm_312_python ?
bdist_linuxarm_313_python ?
bdist_linuxarm_314_python 67.45% <100.00%> (-0.05%) ⬇️
bdist_mac_311_python 67.70% <100.00%> (-0.02%) ⬇️
bdist_mac_312_python ?
bdist_mac_313_python ?
bdist_mac_314_python 67.58% <100.00%> (-0.05%) ⬇️
bdist_win_311_python 67.72% <100.00%> (-0.02%) ⬇️
bdist_win_312_python ?
bdist_win_313_python ?
bdist_win_314_python 67.61% <100.00%> (-0.02%) ⬇️
sdist_linux_311_python ?
sdist_linux_312_python ?
sdist_linux_313_python ?
sdist_linux_314_python ?
sdist_linuxarm_311_python ?
sdist_linuxarm_312_python ?
sdist_linuxarm_313_python ?
sdist_linuxarm_314_python ?
sdist_mac_311_python ?
sdist_mac_312_python ?
sdist_mac_313_python ?
sdist_mac_314_python ?
sdist_win_311_python ?
sdist_win_312_python ?
sdist_win_313_python ?
sdist_win_314_python ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

RegressionTree global and local explanations truncate fractional node predictions

1 participant