Welcome to PyCEbox’s documentation!¶
PyCEbox API¶
-
pycebox.ice.ice(data, column, predict, num_grid_points=None)[source]¶ Generate individual conditional expectation (ICE) curves for a model.
Parameters: - data (
pandasDataFrame) – the sample data from which to generate ICE curves - column (
str) – the name of the column indatathat will be varied to generate ICE curves - predict (callable) – the function that generates predictions from the model.
Must accept a
DataFramewith the same columns asdata. - num_grid_points (
Noneorint) –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 ofdata[column].
Returns: A
DataFramewhose 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: pandasDataFrame- data (
-
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 (
pandasDataFrame) – the ICE data generated bypycebox.ice.ice() - frac_to_plot (
float) – the fraction of ICE curves to plot. If less than one, randomly samples columns ofice_datato plot. - plot_points (
bool) – whether or not to plot the original data points on the ICE curves. In this case,point_kwargsis passed as keyword arguments to plot. - x_quantile (
bool) – ifTrue, the plotted x-coordinates are the quantiles ofice_data.index - plot_pdp – if
True, plot the partial depdendence plot. In this case,pdp_kwargsis passed as keyword arguments toplot. - centered (
bool) – ifTrue, each ICE curve is centered to zero at the percentile closest tocentered_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
DataFrameof the column index ofice_data - cmap (
matplotlibColormap) – - ax (
NoneormatplotlibAxes) – theAxeson which to plot the ICE curves
Other keyword arguments are passed to
plot- ice_data (
-
pycebox.ice.pdp(ice_data)[source]¶ Calculate a partial dependence plot from ICE data
Parameters: ice_data ( pandasDataFrame) – the ICE data generated bypycebox.ice.ice()Returns: the partial dependence plot curve Return type: pandasSeries