Skip to content

plot_partial_dependence


method plot_partial_dependence(models=None, columns=None, kind="average", pair=None, target=1, title=None, legend="lower right", figsize=(900, 600), filename=None, display=True)[source]
Plot the partial dependence of features.

The partial dependence of a feature (or a set of features) corresponds to the response of the model for each possible value of the feature. The plot can take two forms:

  • If pair is None: Single feature partial dependence lines. The deciles of the feature values are shown with tick marks on the bottom.
  • If pair is defined: Two-way partial dependence plots are plotted as contour plots (only allowed for a single model).

Read more about partial dependence on sklearn's documentation. This plot is not available for multilabel nor multiclass-multioutput classification tasks.

Parametersmodels: int, str, Model, slice, sequence or None, default=None
Models to plot. If None, all models are selected.

columns: int, str, slice, sequence or None, default=None
Features to get the partial dependence from. If None, it uses the first 3 features in the dataset.

kind: str or sequence, default="average"
Kind of depedence to plot. Use a sequence or add + between options to select more than one. Choose from:

  • "average": Partial dependence averaged across all samples in the dataset.
  • "individual": Partial dependence for up to 50 random samples (Individual Conditional Expectation).

This parameter is ignored when plotting feature pairs.

pair: int, str or None, default=None
Feature with which to pair the features selected by columns. If specified, the resulting figure displays contour plots. Only allowed when plotting a single model. If None, the plots show the partial dependece of single features.

target: int or str, default=1
Class in the target column to look at (only for multiclass classification tasks).

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

legend: str, dict or None, default="lower right"
Legend for the plot. See the user guide for an extended description of the choices.

  • If None: No legend is shown.
  • If str: Location where to show the legend.
  • If dict: Legend configuration.

figsize: tuple, default=(900, 600)
Figure's size in pixels, format as (x, y).

filename: str 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 html. If None, the plot is not saved.

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

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


See Also

plot_feature_importance

Plot a model's feature importance.

plot_parshap

Plot the partial correlation of shap values.

plot_permutation_importance

Plot the feature permutation importance of models.


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)
>>> atom.run(["LR", "RF"])
>>> atom.plot_partial_dependence(kind="average+individual", legend="upper left")
>>> atom.rf.plot_partial_dependence(columns=(3, 4), pair=2)