Skip to content

plot_shap_waterfall


method plot_shap_waterfall(models=None, rows=0, show=None, target=1, title=None, legend=None, figsize=None, filename=None, display=True)[source]

Plot SHAP's waterfall plot.

The SHAP value of a feature represents the impact of the evidence provided by that feature on the model's output. The waterfall plot is designed to visually display how the SHAP values (evidence) of each feature move the model output from our prior expectation under the background data distribution, to the final model prediction given the evidence of all the features. Features are sorted by the magnitude of their SHAP values with the smallest magnitude features grouped together at the bottom of the plot when the number of features in the models exceeds the show parameter. Read more about SHAP plots in the user guide.

Parameters models: int, str, Model or None, default=None
Model to plot. If None, all models are selected. Note that leaving the default option could raise an exception if there are multiple models. To avoid this, call the plot directly from a model, e.g., atom.lr.plot_shap_waterfall().

rows: int or str, default=0
Selection of rows to plot. The plot_shap_waterfall method does not support plotting multiple samples.

show: int or None, default=None
Number of features (ordered by importance) to show. If None, it shows all features.

target: int, str or tuple, default=1
Class in the target column to target. For multioutput tasks, the value should be a tuple of the form (column, class). Note that for binary and multilabel tasks, the selected class is always the positive one.

title: str, dict or None, default=None
Title for the plot.

legend: str, dict or None, default=None
Do nothing. Implemented for continuity of the API.

figsize: tuple or None, default=None
Figure's size in pixels, format as (x, y). If None, it adapts the size to the number of features shown.

filename: str, Path or None, default=None
Save the plot using this name. Use "auto" for automatic naming. The type of the file depends on the provided name (.html, .png, .pdf, etc...). If filename has no file type, the plot is saved as png. If None, the plot is not saved.

display: bool or None, default=True
Whether to render the plot. If None, it returns the figure.

Returns{#plot_shap_waterfall-plt.Figure or None} plt.Figure or None
Plot object. Only returned if display=None.


See Also

plot_shap_bar

Plot SHAP's bar plot.

plot_shap_beeswarm

Plot SHAP's beeswarm plot.

plot_shap_heatmap

Plot SHAP's heatmap plot.


Example

>>> from atom import ATOMClassifier
>>> from sklearn.datasets import load_breast_cancer

>>> X, y = load_breast_cancer(return_X_y=True, as_frame=True)

>>> atom = ATOMClassifier(X, y, random_state=1)
>>> atom.run("LR")
>>> atom.plot_shap_waterfall(show=10)
atom.plot_shap_waterfall