sklearn.inspection.PartialDependenceDisplay
-
class sklearn.inspection.PartialDependenceDisplay(pd_results, *, features, feature_names, target_idx, pdp_lim, deciles, kind='average', subsample=1000, random_state=None)
[source] -
Partial Dependence Plot (PDP).
This can also display individual partial dependencies which are often referred to as: Individual Condition Expectation (ICE).
It is recommended to use
plot_partial_dependence
to create aPartialDependenceDisplay
. All parameters are stored as attributes.Read more in Advanced Plotting With Partial Dependence and the User Guide.
New in version 0.22.
- Parameters
-
-
pd_resultslist of Bunch
-
Results of
partial_dependence
forfeatures
. -
featureslist of (int,) or list of (int, int)
-
Indices of features for a given plot. A tuple of one integer will plot a partial dependence curve of one feature. A tuple of two integers will plot a two-way partial dependence curve as a contour plot.
-
feature_nameslist of str
-
Feature names corresponding to the indices in
features
. -
target_idxint
-
- In a multiclass setting, specifies the class for which the PDPs should be computed. Note that for binary classification, the positive class (index 1) is always used.
- In a multioutput setting, specifies the task for which the PDPs should be computed.
Ignored in binary classification or classical regression settings.
-
pdp_limdict
-
Global min and max average predictions, such that all plots will have the same scale and y limits.
pdp_lim[1]
is the global min and max for single partial dependence curves.pdp_lim[2]
is the global min and max for two-way partial dependence curves. -
decilesdict
-
Deciles for feature indices in
features
. -
kind{‘average’, ‘individual’, ‘both’}, default=’average’
-
Whether to plot the partial dependence averaged across all the samples in the dataset or one line per sample or both.
-
kind='average'
results in the traditional PD plot; -
kind='individual'
results in the ICE plot.
Note that the fast
method='recursion'
option is only available forkind='average'
. Plotting individual dependencies requires using the slowermethod='brute'
option.New in version 0.24.
-
-
subsamplefloat, int or None, default=1000
-
Sampling for ICE curves when
kind
is ‘individual’ or ‘both’. If float, should be between 0.0 and 1.0 and represent the proportion of the dataset to be used to plot ICE curves. If int, represents the maximum absolute number of samples to use.Note that the full dataset is still used to calculate partial dependence when
kind='both'
.New in version 0.24.
-
random_stateint, RandomState instance or None, default=None
-
Controls the randomness of the selected samples when subsamples is not
None
. See Glossary for details.New in version 0.24.
-
- Attributes
-
-
bounding_ax_matplotlib Axes or None
-
If
ax
is an axes or None, thebounding_ax_
is the axes where the grid of partial dependence plots are drawn. Ifax
is a list of axes or a numpy array of axes,bounding_ax_
is None. -
axes_ndarray of matplotlib Axes
-
If
ax
is an axes or None,axes_[i, j]
is the axes on the i-th row and j-th column. Ifax
is a list of axes,axes_[i]
is the i-th item inax
. Elements that are None correspond to a nonexisting axes in that position. -
lines_ndarray of matplotlib Artists
-
If
ax
is an axes or None,lines_[i, j]
is the partial dependence curve on the i-th row and j-th column. Ifax
is a list of axes,lines_[i]
is the partial dependence curve corresponding to the i-th item inax
. Elements that are None correspond to a nonexisting axes or an axes that does not include a line plot. -
deciles_vlines_ndarray of matplotlib LineCollection
-
If
ax
is an axes or None,vlines_[i, j]
is the line collection representing the x axis deciles of the i-th row and j-th column. Ifax
is a list of axes,vlines_[i]
corresponds to the i-th item inax
. Elements that are None correspond to a nonexisting axes or an axes that does not include a PDP plot.New in version 0.23.
-
deciles_hlines_ndarray of matplotlib LineCollection
-
If
ax
is an axes or None,vlines_[i, j]
is the line collection representing the y axis deciles of the i-th row and j-th column. Ifax
is a list of axes,vlines_[i]
corresponds to the i-th item inax
. Elements that are None correspond to a nonexisting axes or an axes that does not include a 2-way plot.New in version 0.23.
-
contours_ndarray of matplotlib Artists
-
If
ax
is an axes or None,contours_[i, j]
is the partial dependence plot on the i-th row and j-th column. Ifax
is a list of axes,contours_[i]
is the partial dependence plot corresponding to the i-th item inax
. Elements that are None correspond to a nonexisting axes or an axes that does not include a contour plot. -
figure_matplotlib Figure
-
Figure containing partial dependence plots.
-
See also
-
partial_dependence
-
Compute Partial Dependence values.
-
plot_partial_dependence
-
Plot Partial Dependence.
Methods
plot
(*[, ax, n_cols, line_kw, contour_kw])Plot partial dependence plots.
-
plot(*, ax=None, n_cols=3, line_kw=None, contour_kw=None)
[source] -
Plot partial dependence plots.
- Parameters
-
-
axMatplotlib axes or array-like of Matplotlib axes, default=None
-
-
- If a single axis is passed in, it is treated as a bounding axes
-
and a grid of partial dependence plots will be drawn within these bounds. The
n_cols
parameter controls the number of columns in the grid.
-
- If an array-like of axes are passed in, the partial dependence
-
plots will be drawn directly into these axes.
-
-
If None, a figure and a bounding axes is created and treated
-
as the single axes case.
-
-
-
n_colsint, default=3
-
The maximum number of columns in the grid plot. Only active when
ax
is a single axes orNone
. -
line_kwdict, default=None
-
Dict with keywords passed to the
matplotlib.pyplot.plot
call. For one-way partial dependence plots. -
contour_kwdict, default=None
-
Dict with keywords passed to the
matplotlib.pyplot.contourf
call for two-way partial dependence plots.
-
- Returns
-
-
displayPartialDependenceDisplay
-
Examples using sklearn.inspection.PartialDependenceDisplay
© 2007–2020 The scikit-learn developers
Licensed under the 3-clause BSD License.
https://scikit-learn.org/0.24/modules/generated/sklearn.inspection.PartialDependenceDisplay.html