shap.dependence_plot

shap.dependence_plot(ind, shap_values=None, features=None, feature_names=None, display_features=None, interaction_index='auto', color='#1E88E5', axis_color='#333333', cmap=None, dot_size=16, x_jitter=0, alpha=1, title=None, xmin=None, xmax=None, ax=None, show=True)

Create a SHAP dependence plot, colored by an interaction feature.

Plots the value of the feature on the x-axis and the SHAP value of the same feature on the y-axis. This shows how the model depends on the given feature, and is like a richer extenstion of the classical parital dependence plots. Vertical dispersion of the data points represents interaction effects. Grey ticks along the y-axis are data points where the feature’s value was NaN.

Parameters
indint or string

If this is an int it is the index of the feature to plot. If this is a string it is either the name of the feature to plot, or it can have the form “rank(int)” to specify the feature with that rank (ordered by mean absolute SHAP value over all the samples).

shap_valuesnumpy.array

Matrix of SHAP values (# samples x # features).

featuresnumpy.array or pandas.DataFrame

Matrix of feature values (# samples x # features).

feature_nameslist

Names of the features (length # features).

display_featuresnumpy.array or pandas.DataFrame

Matrix of feature values for visual display (such as strings instead of coded values).

interaction_index“auto”, None, int, or string

The index of the feature used to color the plot. The name of a feature can also be passed as a string. If “auto” then shap.common.approximate_interactions is used to pick what seems to be the strongest interaction (note that to find to true stongest interaction you need to compute the SHAP interaction values).

x_jitterfloat (0 - 1)

Adds random jitter to feature values. May increase plot readability when feature is discrete.

alphafloat

The transparency of the data points (between 0 and 1). This can be useful to the show density of the data points when using a large dataset.

xminfloat or string

Represents the lower bound of the plot’s x-axis. It can be a string of the format “percentile(float)” to denote that percentile of the feature’s value used on the x-axis.

xmaxfloat or string

Represents the upper bound of the plot’s x-axis. It can be a string of the format “percentile(float)” to denote that percentile of the feature’s value used on the x-axis.

axmatplotlib Axes object

Optionally specify an existing matplotlib Axes object, into which the plot will be placed. In this case we do not create a Figure, otherwise we do.