CARLA
CARLA: A Python Library to Benchmark Algorithmic Recourse and Counterfactual Explanation Algorithms
Install / Use
/learn @carla-recourse/CARLAREADME
CARLA - Counterfactual And Recourse Library
<img align="right" width="240" height="200" src="https://github.com/carla-recourse/CARLA/blob/main/images/carla_logo_square.png?raw=true">CARLA is a python library to benchmark counterfactual explanation and recourse models. It comes out-of-the box with commonly used datasets and various machine learning models. Designed with extensibility in mind: Easily include your own counterfactual methods, new machine learning models or other datasets. Find extensive documentation here! Our arXiv paper can be found here.
What is algorithmic recourse? As machine learning (ML) models are increasingly being deployed in high-stakes applications, there has been growing interest in providing recourse to individuals adversely impacted by model predictions (e.g., below we depict the canonical recourse example for an applicant whose loan has been denied). This library provides a starting point for researchers and practitioners alike, who wish to understand the inner workings of various counterfactual explanation and recourse methods and their underlying assumptions that went into the design of these methods.

Notebooks / Examples
- Getting Started (notebook): Source
- Causal Recourse (notebook): Source
- Plotting (notebook): Source
- Benchmarking (notebook): Source
- Adding your own Data: Source
- Adding your own ML-Model: Source
- Adding your own Recourse Method: Source
Available Datasets
| Name | Source | |---------------------|----------------------------------------------------------------------------------------------| | Adult | Source | | COMPAS | Source | | Give Me Some Credit | Source | | HELOC | Source |
Provided Machine Learning Models
| Model | Description | Tensorflow | Pytorch | Sklearn | XGBoost | |--------------|:----------------------------------------------------------------------------:|:----------:|:-------:|:-------:|:-------:| | ANN | Artificial Neural Network with 2 hidden layers and ReLU activation function. | X | X | | | | LR | Linear Model with no hidden layer and no activation function. | X | X | | | | RandomForest | Tree Ensemble Model. | | | X | | | XGBoost | Gradient boosting. | | | | X |
Implemented Counterfactual methods
The framework a counterfactual method currently works with is dependent on its underlying implementation. It is planned to make all recourse methods available for all ML frameworks . The latest state can be found here:
| Recourse Method | Paper | Tensorflow | Pytorch | SKlearn | XGBoost | |------------------------------------------------------------|:-----------------------------------------------------------------|:----------:|:-------:|:-------:|:-------:| | Actionable Recourse (AR) | Source | X | X | | | | Causal Recourse | Source | X | X | | | | CCHVAE | Source | | X | | | | Contrastive Explanations Method (CEM) | Source | X | | | | | Counterfactual Latent Uncertainty Explanations (CLUE) | Source | | X | | | | CRUDS | Source | | X | | | | Diverse Counterfactual Explanations (DiCE) | Source | X | X | | | | Feasible and Actionable Counterfactual Explanations (FACE) | Source | X | X | | | | FeatureTweak | Source | | | X | X | | FOCUS | Source | | | X | X | | Growing Spheres (GS) | Source | X | X | | | | Revise | Source | | X | | | | Wachter | Source | | X | | |
Installation
Requirements
python3.7pip
Install via pip
pip install carla-recourse
Quickstart
from carla import OnlineCatalog, MLModelCatalog
from carla.recourse_methods import GrowingSpheres
# load a catalog dataset
data_name = "adult"
dataset = OnlineCatalog(data_name)
# load artificial neural network from catalog
model = MLModelCatalog(dataset, "ann")
# get factuals from the data to generate counterfactual examples
factuals = dataset.raw.iloc[:10]
# load a recourse model and pass black box model
gs = GrowingSpheres(model)
# generate counterfactual examples
counterfactuals = gs.get_counterfactuals(factuals)
Contributing
Requirements
python3.7-venv(when not already shipped with python3.7)- Recommended: GNU Make
Installation
Using make:
make requirements
Using python directly or within activated virtual environment:
pip install -U pip setuptools wheel
pip install -e .
Testing
Using make:
make test
Using python directly or within activated virtual environment:
pip install -r requirements-dev.txt
python -m pytest test/*
Linting and Styling
We use pre-commit hooks within our build pipelines to enforce:
Install pre-commit with:
make install-dev
Using python directly or within activated virtual environment:
pip install -r requirements-dev.txt
pre-commit install
Licence
carla is under the MIT Licence. See the LICENCE for more details.
Citation
This project was recently accepted to NeurIPS 2021 (Benchmark & Data Sets Track). If you use this codebase, please cite:
@misc{pawelczyk2021carla,
title={CARLA: A Python Library to Benchmark Algorithmic Recourse and Counterfactual Explanation Algorithms},
author={Martin Pawelczyk and Sascha Bielawski and Johannes van den Heuvel and Tobias Richter and Gjergji Kasneci},
year={2021},
eprint={2108.00783},
archivePrefix={arXiv},
primaryClass={cs.LG}
}
Please also cite the original authors' work.
Related Skills
claude-opus-4-5-migration
83.3kMigrate prompts and code from Claude Sonnet 4.0, Sonnet 4.5, or Opus 4.1 to Opus 4.5
model-usage
337.7kUse CodexBar CLI local cost usage to summarize per-model usage for Codex or Claude, including the current (most recent) model or a full model breakdown. Trigger when asked for model-level usage/cost data from codexbar, or when you need a scriptable per-model summary from codexbar cost JSON.
TrendRadar
49.8k⭐AI-driven public opinion & trend monitor with multi-platform aggregation, RSS, and smart alerts.🎯 告别信息过载,你的 AI 舆情监控助手与热点筛选工具!聚合多平台热点 + RSS 订阅,支持关键词精准筛选。AI 智能筛选新闻 + AI 翻译 + AI 分析简报直推手机,也支持接入 MCP 架构,赋能 AI 自然语言对话分析、情感洞察与趋势预测等。支持 Docker ,数据本地/云端自持。集成微信/飞书/钉钉/Telegram/邮件/ntfy/bark/slack 等渠道智能推送。
mcp-for-beginners
15.7kThis open-source curriculum introduces the fundamentals of Model Context Protocol (MCP) through real-world, cross-language examples in .NET, Java, TypeScript, JavaScript, Rust and Python. Designed for developers, it focuses on practical techniques for building modular, scalable, and secure AI workflows from session setup to service orchestration.
