pyCeterisParibus: explaining Machine Learning models with Ceteris Paribus Profiles in Python

Michal Kuzba, Ewa Baranowska, Przemyslaw Biecek, Michał KuźbaJ. Open Source Softw 2019 · DOI · DBLP

Introduction

As machine learning models grow in complexity—often involving ensembles with millions of parameters—they increasingly behave like "black boxes." This lack of interpretability poses significant risks, including biased decision-making and difficult-to-trace data drift. Furthermore, legal frameworks like the GDPR have introduced a "Right to Explanation," requiring organizations to justify automated decisions. While global explanation tools exist, there is a persistent need for "local" explanations—understanding why a model made a specific decision for a specific individual.

pyCeterisParibus is a Python library designed to address these challenges by generating "What-If" scenarios for individual predictions. By varying one feature while keeping all others constant—a principle known as Ceteris Paribus—the tool allows developers to visualize how specific variables drive a model's output, making AI more transparent and easier to debug.

Methodology

The pyCeterisParibus library implements Ceteris Paribus Profiles (Latin for "all else unchanged"). It is designed to be model-agnostic, working with any machine learning model through a unified wrapper around the model’s prediction interface. Unlike Partial Dependency Plots (PDP), which show average effects across a dataset, these profiles focus on local explanations, serving as an extension of Individual Conditional Expectation (ICE) plots.

Key technical features include:

  • Interactive Visualizations: Utilizing a D3.js-based engine to produce interactive plots where users can hover for details or filter data through an integrated table.
  • Neighbor Analysis: Sampling "neighboring" observations using Gower’s distance to compare a specific data point against similar instances (e.g., comparing a specific passenger to other similar passengers).
  • Model Comparison: Simultaneous plotting of multiple models (e.g., XGBoost vs. Random Forest) to compare how different architectures interpret the same individual.

Case Study: Titanic Survival

The utility of pyCeterisParibus is demonstrated using the Titanic dataset, a classic benchmark for predicting survival probability. The tool provides an "aha moment" by allowing users to see counterfactual realities for specific passengers.

Ceteris Paribus profile for Age, showing the non-linear relationship with survival probability.

As illustrated in the figure above, for a 19-year-old passenger, the model predicts a low survival probability. However, the profile instantly shows that had the passenger been a child (under age 10), the predicted survival probability would have spiked significantly. This successfully visualizes the non-linear relationship between age and survival, identifying specific "drop-off" points in the model's logic.

Validation of Feature Importance

The library also serves as a functional tool for validating model logic against historical expectations. By examining individual profiles, researchers can confirm which features dominate a prediction.

Ceteris Paribus profile for Passenger Class (Pclass), demonstrating the impact of socioeconomic status on survival.

In the Titanic case study, the tool validates that "Class" and "Sex" are dominant predictors. The profile for Pclass shows a clear decline in survival probability from first to third class, aligning with historical records. The integration of a searchable, filterable table alongside these plots allows researchers to move from high-level visual trends to raw data inspection seamlessly.

Discussion and Limitations

While powerful, pyCeterisParibus faces challenges common to local explanation methods. The core assumption that features can be changed independently (the Ceteris Paribus assumption) may lead to evaluating models on "unrealistic" data points if features are highly correlated. For example, changing "Education Level" without changing "Age" might create a logically impossible data point for the model to process.

Furthermore, while excellent for individual cases, the method does not scale visually to thousands of observations simultaneously. Future work for the package involves expanding customization options and refining the handling of feature dependencies to provide even more robust local explanations for complex machine learning systems.

Summary updated

BibTeX
@article{kuzba2019pyceterisparibus,
  author = {Michal Kuzba and Ewa Baranowska and Przemyslaw Biecek and Michał Kuźba},
  title = {{pyCeterisParibus: explaining Machine Learning models with Ceteris Paribus Profiles in Python}},
  journal = {J. Open Source Softw.},
  year = {2019},
  doi = {10.21105/joss.01389},
}
Figure