Thanks to visit codestin.com
Credit goes to github.com

Skip to content

BUG: summary_plot displays only one feature in shap>=0.47.0 #4081

@aazuspan

Description

@aazuspan

Issue Description

Following the NHANES I Survival Model notebook with shap>=0.47.0 produces a summary plot with only one feature (shown below), instead of the 7x7 matrix shown here.

Image

This might be related to several of the comments on #804, but not to the original issue which is unrelated (this isn't caused by max_display).

Minimal Reproducible Example

# Adapted from https://shap.readthedocs.io/en/latest/example_notebooks/tabular_examples/tree_based_models/NHANES%20I%20Survival%20Model.html

from sklearn.model_selection import train_test_split
import shap
import xgboost

X, y = shap.datasets.nhanesi()

# human readable feature values
X_display, y_display = shap.datasets.nhanesi(display=True)

xgb_full = xgboost.DMatrix(X, label=y)

# create a train/test split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=7)
xgb_train = xgboost.DMatrix(X_train, label=y_train)
xgb_test = xgboost.DMatrix(X_test, label=y_test)

# train final model on the full data set
params = {"eta": 0.002, "max_depth": 3, "objective": "survival:cox", "subsample": 0.5}
model = xgboost.train(params, xgb_full, 5000, evals=[(xgb_full, "test")], verbose_eval=1000)

number_patients = 300
shap_interaction_values = shap.TreeExplainer(model).shap_interaction_values(X.iloc[:number_patients, :])
shap.summary_plot(shap_interaction_values, X.iloc[:number_patients, :])

Traceback

Expected Behavior

The code should generate the figure below:

Image

Bug report checklist

  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest release of shap.
  • I have confirmed this bug exists on the master branch of shap.
  • I'd be interested in making a PR to fix this bug

Installed Versions

I've confirmed the bug is present in:

  • 0.47.0
  • 0.47.2
  • master

It is not present in 0.46.0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIndicates an unexpected problem or unintended behaviourregressionRegression bugs - worked once, not anymorevisualizationRelating to plotting

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions