BASIC XAI with DALEX — Part 7: Ceteris Paribus profiles

Anna Kozak
Jan 17 · 4 min read

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


Having Fun while building Responsible ML models

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

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