Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Label dots in scatterplot according to classes and add a legend #3529

Open
sroener opened this issue Feb 28, 2024 · 0 comments
Open

ENH: Label dots in scatterplot according to classes and add a legend #3529

sroener opened this issue Feb 28, 2024 · 0 comments
Labels
enhancement Indicates new feature requests visualization Relating to plotting

Comments

@sroener
Copy link
Contributor

sroener commented Feb 28, 2024

Problem Description

Hi,

I decided to interpret a few of my models using shap. To get a good grasp on the most important features, I want to plot them using shap.scatter and see how the shap values are based on the feature value distribution. To make these plots even more meaningful, I would like to add color to the dots according to their respective class labels.

Alternative Solutions

I tried producing an example based on one of the official examples for the scatterplot:

import sklearn.linear_model
import shap

X, y = shap.datasets.adult()
model = sklearn.linear_model.LogisticRegression(max_iter = 10000).fit(X,y)

explainer = shap.Explainer(lambda x: model.predict_proba(x)[:, 1], X)
shap_values = explainer(X[:1000])

shap.plots.scatter(shap_values[:, "Age"], color=y[:1000]) #limit y to 1000, equal to the shap_values 

The following plot shows the output of the code:

Dummy_scatter_class

This solution kind of works, but abusing the color option feels a bit hacky and the colorbar representing the classes is also suboptimal.

@sroener sroener added the enhancement Indicates new feature requests label Feb 28, 2024
@connortann connortann added the visualization Relating to plotting label Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Indicates new feature requests visualization Relating to plotting
Projects
None yet
Development

No branches or pull requests

2 participants