Skip to content

plot_partial_dependence


method plot_partial_dependence(models=None, columns=(0, 1, 2), 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.

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

columns: int, str, segment, sequence or dataframe, default=(0, 1, 2)
Feature set to get the partial dependence from.

kind: str or sequence, default="average"
Kind of dependence 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 dependence 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: Position to display the legend.
  • If dict: Legend configuration.

figsize: tuple, default=(900, 600)
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 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.

Returns{#plot_partial_dependence-go.Figure or None} go.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, random_state=1)
>>> atom.run(["LR", "RF"])
>>> atom.plot_partial_dependence(kind="average+individual", legend="upper left")

>>> atom.rf.plot_partial_dependence(columns=(3, 4), pair=2)