pdpbox.pdp.pdp_interact_plot

pdpbox.pdp.pdp_interact_plot(pdp_interact_out, feature_names, plot_type='contour', x_quantile=False, plot_pdp=False, which_classes=None, figsize=None, ncols=2, plot_params=None)

PDP interact

Parameters:
pdp_interact_out: (list of) instance of PDPInteract

for multi-class, it is a list

feature_names: list

[feature_name1, feature_name2]

plot_type: str, optional, default=’contour’

type of the interact plot, can be ‘contour’ or ‘grid’

x_quantile: bool, default=False

whether to construct x axis ticks using quantiles

plot_pdp: bool, default=False

whether to plot pdp for each feature

which_classes: list, optional, default=None

which classes to plot, only use when it is a multi-class problem

figsize: tuple or None, optional, default=None

size of the figure, (width, height)

ncols: integer, optional, default=2

number subplot columns, used when it is multi-class problem

plot_params: dict or None, optional, default=None

parameters for the plot, possible parameters as well as default as below:

plot_params = {
    # plot title and subtitle
    'title': 'PDP interact for "%s" and "%s"',
    'subtitle': 'Number of unique grid points: (%s: %d, %s: %d)',
    'title_fontsize': 15,
    'subtitle_fontsize': 12,
    # color for contour line
    'contour_color':  'white',
    'font_family': 'Arial',
    # matplotlib color map for interact plot
    'cmap': 'viridis',
    # fill alpha for interact plot
    'inter_fill_alpha': 0.8,
    # fontsize for interact plot text
    'inter_fontsize': 9,
}
Returns:
fig: matplotlib Figure
axes: a dictionary of matplotlib Axes

Returns the Axes objects for further tweaking

Examples

Quick start with pdp_interact_plot

from pdpbox import pdp, get_dataset

test_titanic = get_dataset.titanic()
titanic_data = test_titanic['data']
titanic_target = test_titanic['target']
titanic_features = test_titanic['features']
titanic_model = test_titanic['xgb_model']

inter1 = pdp.pdp_interact(model=titanic_model,
                          dataset=titanic_data,
                          model_features=titanic_features,
                          features=['Age', 'Fare'],
                          num_grid_points=[10, 10],
                          percentile_ranges=[(5, 95), (5, 95)])
fig, axes = pdp.pdp_interact_plot(pdp_interact_out=inter1,
                                  feature_names=['age', 'fare'],
                                  plot_type='contour',
                                  x_quantile=True,
                                  plot_pdp=True)

With multi-class

from pdpbox import pdp, get_dataset

test_otto = get_dataset.otto()
otto_data = test_otto['data']
otto_features = test_otto['features']
otto_model = test_otto['rf_model']
otto_target = test_otto['target']

pdp_67_24_rf = pdp.pdp_interact(model=otto_model,
                                dataset=otto_data,
                                model_features=otto_features,
                                features=['feat_67', 'feat_24'],
                                num_grid_points=[10, 10],
                                percentile_ranges=[None, None],
                                n_jobs=4)
fig, axes = pdp.pdp_interact_plot(pdp_interact_out=pdp_67_24_rf,
                                  feature_names=['feat_67', 'feat_24'],
                                  plot_type='grid',
                                  x_quantile=True,
                                  ncols=2,
                                  plot_pdp=False,
                                  which_classes=[1, 2, 3])