Generating Collective Counterfactual Explanations in Score-based Classification via Mathematical Optimization

Emilio Carrizosa, Jasone Ramírez-Ayerbe*, Dolores Romero Morales

*Corresponding author for this work

Research output: Contribution to journalJournal articleResearchpeer-review


Due to the increasing use of Machine Learning models in high stakes decision making settings, it has become increasingly important to have tools to understand how models arrive at decisions. Assuming an already trained Supervised Classification model, post-hoc explanations can be obtained via so-called counterfactual analysis: a counterfactual explanation of an instance indicates how this instance should be minimally modified so that the perturbed instance is classified in the desired class by the given Machine Learning classification model.

Most of the Counterfactual Analysis literature focuses on the single-instance single-counterfactual setting, in which the analysis is done for one single instance to provide one single counterfactual explanation. Taking a stakeholder’s perspective, in this paper we introduce the so-called collective counterfactual explanations. By means of novel Mathematical Optimization models, we provide a counterfactual explanation for each instance in a group of interest, so that the total cost of the perturbations is minimized under some linking constraints. Making the process of constructing counterfactuals collective instead of individual enables us to detect the features that are critical to the entire dataset to have the individuals classified in the desired class. Our methodology allows for some instances to be treated individually, as in the single-instance single-counterfactual case, performing the collective counterfactual analysis for a fraction of records of the group of interest. This way, outliers are identified and handled appropriately.

Under some assumptions on the classifier and the space in which counterfactuals are sought, finding collective counterfactual explanations is reduced to solving a convex quadratic linearly constrained mixed integer optimization problem, which, for datasets of moderate size, can be solved to optimality using existing solvers.

The performance of our approach is illustrated on real-world datasets, demonstrating its usefulness.
Original languageEnglish
Article number121954
JournalExpert Systems with Applications
Issue numberPart D
Number of pages27
Publication statusPublished - Mar 2024

Bibliographical note

Published online: 13 October 2023.


  • Collective counterfactual explanations
  • Mathematical optimization
  • Explainable machine learning
  • Linear models
  • Random forests

Cite this