Skip to content

feat: add waterfall plot for local explanations (#453) - #698

Open
laasyapriya2007 wants to merge 2 commits into
interpretml:mainfrom
laasyapriya2007:waterfall-local-explanation
Open

laasyapriya2007 wants to merge 2 commits into
interpretml:mainfrom
laasyapriya2007:waterfall-local-explanation

Conversation

@laasyapriya2007

Copy link
Copy Markdown

Description

This PR resolves #453 by adding support for waterfall plots in local explanations.

Waterfall charts are one of the most effective and widely-used ways to visualize local additive feature attributions (similar to SHAP waterfall plots), clearly illustrating how the prediction is obtained starting from the base value (Intercept), through individual feature score contributions, to the final model Prediction.

Key Changes

  1. plot_waterfall in interpret.visual.plot:
    • Generates Plotly go.Waterfall charts for local explanation data dictionaries.
    • Starts with Intercept as the baseline, cascades each sorted feature score contribution, and terminates with a total bar for Prediction.
    • Supports both horizontal (orientation="h", default) and vertical (orientation="v") orientations.
    • Supports configurable top_n (defaults to 15), automatically aggregating the remaining lower-magnitude terms into an "Other features" step.
    • Handles regression, binary classification, and multiclass models (allowing class_idx selection).
  2. Local Explanation API (visualize and show):
    • FeatureValueExplanation.visualize(key, plot_type="waterfall")
    • EBMExplanation.visualize(key, plot_type="waterfall")
    • LinearExplanation.visualize(key, plot_type="waterfall")
    • Compatible with interpret.show(local_exp, key=0, plot_type="waterfall") and inline / preserve providers.
  3. Unit Tests:
    • Added comprehensive tests in tests/visual/test_plot.py covering basic waterfall generation, vertical layout, top_n grouping, multiclass support, and model explanation visualization.

How to Test

import numpy as np
from interpret.glassbox import ExplainableBoostingRegressor

X = np.random.randn(100, 3)
y = 2.0 * X[:, 0] - 1.5 * X[:, 1] + 5.0

ebm = ExplainableBoostingRegressor(max_rounds=5, outer_bags=1)
ebm.fit(X, y)
local_exp = ebm.explain_local(X[:2], y[:2])

# Render waterfall plot
fig = local_exp.visualize(0, plot_type="waterfall")
fig.show()

laasyapriya2007 and others added 2 commits October 23, 2026 15:31
Add plot_waterfall in interpret.visual.plot and support plot_type='waterfall' in local explanation visualize() and show().

- Implements plot_waterfall to visualize instance score breakdown from intercept to final prediction.
- Supports both horizontal and vertical orientations and configurable top_n with remaining features aggregation.
- Extends FeatureValueExplanation, EBMExplanation, and LinearExplanation visualize() to support plot_type='waterfall'.
- Adds unit tests for regression, binary, and multiclass waterfall visualizations.

Signed-off-by: Laasya Priya <laasyapriya1234@gmail.com>
@codecov

codecov Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.25287% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 67.46%. Comparing base (d82ea62) to head (71f3461).

Files with missing lines Patch % Lines
python/interpret-core/interpret/visual/plot.py 94.11% 4 Missing ⚠️
python/interpret-core/interpret/glassbox/_ebm.py 87.50% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #698      +/-   ##
==========================================
+ Coverage   67.32%   67.46%   +0.14%     
==========================================
  Files          77       77              
  Lines       11739    11815      +76     
==========================================
+ Hits         7903     7971      +68     
- Misses       3836     3844       +8     
Flag Coverage Δ
bdist_linux_311_python 67.21% <94.25%> (+0.16%) ⬆️
bdist_linux_312_python ?
bdist_linux_313_python ?
bdist_linux_314_python 67.12% <94.25%> (+0.16%) ⬆️
bdist_linuxarm_311_python 67.23% <94.25%> (+0.16%) ⬆️
bdist_linuxarm_312_python ?
bdist_linuxarm_313_python ?
bdist_linuxarm_314_python 67.14% <94.25%> (+0.16%) ⬆️
bdist_mac_311_python 67.36% <94.25%> (+0.14%) ⬆️
bdist_mac_312_python ?
bdist_mac_313_python ?
bdist_mac_314_python 67.28% <94.25%> (+0.16%) ⬆️
bdist_win_311_python 67.41% <94.25%> (+0.15%) ⬆️
bdist_win_312_python ?
bdist_win_313_python ?
bdist_win_314_python 67.30% <94.25%> (+0.16%) ⬆️
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.

Add waterfall plot for local explanations

1 participant