Welcome to PyCEbox’s documentation!

Introduction

For a walkthrough of pycebox‘s functionality, see the Tutorial.

PyCEbox API

pycebox.ice.ice(data, column, predict, num_grid_points=None)[source]

Generate individual conditional expectation (ICE) curves for a model.

Parameters:
  • data (pandas DataFrame) – the sample data from which to generate ICE curves
  • column (str) – the name of the column in data that will be varied to generate ICE curves
  • predict (callable) – the function that generates predictions from the model. Must accept a DataFrame with the same columns as data.
  • num_grid_points (None or int) –

    the number of grid points to use for the independent variable of the ICE curves. The independent variable values for the curves will be quantiles of the data.

    If None, the values of the independent variable will be the unique values of data[column].

Returns:

A DataFrame whose columns are ICE curves. The row index is the independent variable, and the column index is the original data point corresponding to that ICE curve.

Return type:

pandas DataFrame

pycebox.ice.ice_plot(ice_data, frac_to_plot=1.0, plot_points=False, point_kwargs=None, x_quantile=False, plot_pdp=False, centered=False, centered_quantile=0.0, color_by=None, cmap=None, ax=None, pdp_kwargs=None, **kwargs)[source]

Plot the ICE curves

Parameters:
  • ice_data (pandas DataFrame) – the ICE data generated by pycebox.ice.ice()
  • frac_to_plot (float) – the fraction of ICE curves to plot. If less than one, randomly samples columns of ice_data to plot.
  • plot_points (bool) – whether or not to plot the original data points on the ICE curves. In this case, point_kwargs is passed as keyword arguments to plot.
  • x_quantile (bool) – if True, the plotted x-coordinates are the quantiles of ice_data.index
  • plot_pdp – if True, plot the partial depdendence plot. In this case, pdp_kwargs is passed as keyword arguments to plot.
  • centered (bool) – if True, each ICE curve is centered to zero at the percentile closest to centered_quantile.
  • color_by (None, str, or callable) –

    If a string, color the ICE curve by that level of the column index.

    If callable, color the ICE curve by its return value when applied to a DataFrame of the column index of ice_data

  • cmap (matplotlib Colormap) –
  • ax (None or matplotlib Axes) – the Axes on which to plot the ICE curves

Other keyword arguments are passed to plot

pycebox.ice.pdp(ice_data)[source]

Calculate a partial dependence plot from ICE data

Parameters:ice_data (pandas DataFrame) – the ICE data generated by pycebox.ice.ice()
Returns:the partial dependence plot curve
Return type:pandas Series

Indices and tables