Published in



BASIC XAI with DALEX — Part 7: Ceteris Paribus profiles

Introduction to model exploration with code examples for R and Python.

By Anna Kozak

Welcome to the “BASIC XAI with DALEX” series.

In this post, we present the Ceteris Paribus profiles, the model agnostic method, which is the one we can use for any type of model.

Previous parts of this series are available:

So, shall we start?

First — What Ceteris Paribus deliver to us?

Ceteris Paribus is a Latin phrase meaning “other things held constant” or “all else unchanged”. Ceteris Paribus (CP) profiles are designed to show model response around a single point in the feature space. They show how the model response depends on changes in a single input variable, keeping all other variables unchanged. They work for any Machine Learning model and allow for model comparisons to better understand how a model is working.

Second — Idea of Ceteris Paribus

Lef f denote a predictive model. Ceteris Paribus profiles for model f, variable j, and point x₊ are defined as

where x₊ refers to a point in the feature space. Moreover x ʲ|⁼ ᶻ denotes a data point x₊ with all coordinates equal to x₊ except coordinate j equal to value z.

Look at the example for observation x₊, which takes the value 1998 for the year of construction, 88 for the surface, 2 for the number of floors, and 3 for the number of rooms. Variable j is a construcion.year, so it only takes different values and the other variables have values for observation x₊.

The Figure below shows the CP profile for a single observation described above. The purple dot is a value of prediction for x₊, j is feature construction.year and z takes value from the range 1920 to 2010.

Ceteris Paribus profile, the violet dot indicates the prediction value for observation, the line indicates the Ceteris Paribus profile. On the x-axis, we have values of the variable construction.year, and on the y-axis we have the prediction value for observations when only the value of the variable construction.year changes.

Third — let’s get a model in R and Python

Let’s write some code. We are still working on the DALEX apartments data. To calculate the Ceteris Paribus profile we use the predict_profile() function. We need the explainer object and the observation for which we want to calculate the explanation. Then using the plot() function we plot the CP profile.

Code to created predict_profile object in Python and R

In the figure below we have profiles for variables like construction.year, surface, floor, and no.rooms. Analyzing it we can read that if our property was built before 1935 or after 2000 its price could be higher. Moreover let’s look at the surface variable, if our apartment had a smaller surface its price would go up, but increasing the surface by every additional meter decreases it.

Ceteris Paribus profiles

To evaluate how the prediction for selected observations behaves, we can draw several Ceteris Paribus profiles. See an example below. Each profile corresponds to one observation from the subset (the plot corresponds to 10 randomly selected observations). To get this plot, we must provide a data frame containing the selected number of observations as the value of the new_observation argument.

Ceteris Paribus profile for 10 randomly selected observation

This is the last part of the “BASIC XAI with DALEX” series, thank you for the time you spent with me on this incredible XAI adventure.

If you are interested in other posts about explainable, fair, and responsible ML, follow #ResponsibleML on Medium.

In order to see more R related content visit




Tools for Explainable, Fair and Responsible ML.

Recommended from Medium

Optical Recognition System in Natural Scenes

#APaperADay S1E6: Interpretability Beyond Feature Attribution: Quantitative Testing with Concept…

Building an M&M Colour Classifier

How to bring your neural network to the web

Neural Machine Translation using Simple Seq2Seq

DeepLab: Semantic Image Segmentation with Deep Convolutional Nets, Atrous Convolution, and Fully…

Scrape Instagram Profiles without Coding [Free]

Boosting Techniques in Python: Predicting Hotel Cancellations

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Anna Kozak

Anna Kozak

Data Scientist | Data Visualization | Responsible Machine Learning

More from Medium

How to convert between Seurat/SingleCellExperiment object and Scanpy object/AnnData using basic…

Simulation-based linear mixed effect regression models with stan

How To Use Logic Operators in R Programming For Data Model Accuracy

Relative Importance of Variables for Explainable AI: Shapley Values and Linear Regression