shap.decision_plot

shap.decision_plot(base_value, shap_values, features=None, feature_names=None, feature_order='importance', feature_display_range=None, highlight=None, link='identity', plot_color=None, axis_color='#333333', y_demarc_color='#333333', alpha=None, color_bar=True, auto_size_plot=True, title=None, xlim=None, show=True, return_objects=False, ignore_warnings=False, new_base_value=None, legend_labels=None, legend_location='best') → Optional[shap.plots._decision.DecisionPlotResult]

Visualize model decisions using cumulative SHAP values.

Each plotted line explains a single model prediction. If a single prediction is plotted, feature values will be printed in the plot (if supplied). If multiple predictions are plotted together, feature values will not be printed. Plotting too many predictions together will make the plot unintelligible.

Parameters
base_valuefloat or numpy.ndarray

This is the reference value that the feature contributions start from. Usually, this is explainer.expected_value.

shap_valuesnumpy.ndarray

Matrix of SHAP values (# features) or (# samples x # features) from explainer.shap_values(). Or cube of SHAP interaction values (# samples x # features x # features) from explainer.shap_interaction_values().

featuresnumpy.array or pandas.Series or pandas.DataFrame or numpy.ndarray or list

Matrix of feature values (# features) or (# samples x # features). This provides the values of all the features and, optionally, the feature names.

feature_nameslist or numpy.ndarray

List of feature names (# features). If None, names may be derived from the features argument if a Pandas object is provided. Otherwise, numeric feature names will be generated.

feature_orderstr or None or list or numpy.ndarray

Any of “importance” (the default), “hclust” (hierarchical clustering), “none”, or a list/array of indices.

feature_display_range: slice or range

The slice or range of features to plot after ordering features by feature_order. A step of 1 or None will display the features in ascending order. A step of -1 will display the features in descending order. If feature_display_range=None, slice(-1, -21, -1) is used (i.e. show the last 20 features in descending order). If shap_values contains interaction values, the number of features is automatically expanded to include all possible interactions: N(N + 1)/2 where N = shap_values.shape[1].

highlightAny

Specify which observations to draw in a different line style. All numpy indexing methods are supported. For example, list of integer indices, or a bool array.

linkstr

Use “identity” or “logit” to specify the transformation used for the x-axis. The “logit” link transforms log-odds into probabilities.

plot_colorstr or matplotlib.colors.ColorMap

Color spectrum used to draw the plot lines. If str, a registered matplotlib color name is assumed.

axis_colorstr or int

Color used to draw plot axes.

y_demarc_colorstr or int

Color used to draw feature demarcation lines on the y-axis.

alphafloat

Alpha blending value in [0, 1] used to draw plot lines.

color_barbool

Whether to draw the color bar.

auto_size_plotbool

Whether to automatically size the matplotlib plot to fit the number of features displayed. If False, specify the plot size using matplotlib before calling this function.

titlestr

Title of the plot.

xlim: tuple[float, float]

The extents of the x-axis (e.g. (-1.0, 1.0)). If not specified, the limits are determined by the maximum/minimum predictions centered around base_value when link=’identity’. When link=’logit’, the x-axis extents are (0, 1) centered at 0.5. x_lim values are not transformed by the link function. This argument is provided to simplify producing multiple plots on the same scale for comparison.

showbool

Whether to automatically display the plot.

return_objectsbool

Whether to return a DecisionPlotResult object containing various plotting features. This can be used to generate multiple decision plots using the same feature ordering and scale.

ignore_warningsbool

Plotting many data points or too many features at a time may be slow, or may create very large plots. Set this argument to True to override hard-coded limits that prevent plotting large amounts of data.

new_base_valuefloat

SHAP values are relative to a base value; by default, the expected value of the model’s raw predictions. Use new_base_value to shift the base value to an arbitrary value (e.g. the cutoff point for a binary classification task).

legend_labelslist of str

List of legend labels. If None, legend will not be shown.

legend_locationstr

Legend location. Any of “best”, “upper right”, “upper left”, “lower left”, “lower right”, “right”, “center left”, “center right”, “lower center”, “upper center”, “center”.

Returns
DecisionPlotResult or None

Returns a DecisionPlotResult object if return_objects=True. Returns None otherwise (the default).