Skip to content

plot_shap_force


method plot_shap_force(models=None, rows="test", target=1, title=None, legend=None, figsize=(900, 300), filename=None, display=True, **kwargs)[source]
Plot SHAP's force plot.

Visualize the given SHAP values with an additive force layout. Note that by default this plot will render using javascript. For a regular figure use matplotlib=True (this option is only available when only a single sample is plotted). Read more about SHAP plots in the user guide.

Parametersmodels: 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_force().

rows: hashable, segment, sequence or dataframe, default="test"
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=(900, 300)
Figure's size in pixels, format as (x, y).

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 (only if matplotlib=True in kwargs).

**kwargs
Additional keyword arguments for shap.plots.force.

Returnsplt.Figure or None
Plot object. Only returned if display=None.


See Also

plot_shap_beeswarm

Plot SHAP's beeswarm plot.

plot_shap_scatter

Plot SHAP's scatter plot.

plot_shap_decision

Plot SHAP's decision 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_force(rows=-2, matplotlib=True, figsize=(1800, 300))
c0a393c1-049d-435d-8c65-d94166186179.png