carla-counterfactual-eval
Overlap Number of Balls Model-Agnostic CounterFactuals (ONB-MACF): A Data-Morphology-based Counterfactual Generation Method for Trustworthy Artificial Intelligence — Pascual-Triana et al. (2024) (arXiv:2405.12326, 2024)
What this evaluates
Evaluates the quality and feasibility of model-agnostic counterfactual explanations generated for tabular data. It probes whether generated counterfactuals successfully flip classifier predictions while maintaining sparsity, proximity, actionability (immutable constraints), and plausibility across multiple binary classification tasks.
Datasets
- adult — total 24416; splits: test (200)
- COMPAS — total 6172; splits: test (200)
- Give Me Some Credit — total 23105; splits: test (200)
- HELOC — total 9871; splits: test (200)
- Irish — total 500; splits: test (200)
- Saheart — total 462; splits: test (200)
- Titanic — total 2099; splits: test (200)
- Wine — total 4898; splits: test (200)
Metrics
L0 norm — range: other
- Counts the number of attributes that change between the factual sample and its counterfactual. Measures sparsity.
L1 norm — range: other
- Computes the Manhattan distance between the factual sample and its counterfactual. Measures proximity/closeness.
L2 norm — range: other
- Computes the squared Euclidean distance between the factual sample and its counterfactual. Measures proximity/closeness.
L∞ norm — range: other
- Computes the maximum absolute difference across features between the factual sample and its counterfactual. Measures proximity/closeness.
Constraint violation — range: other
- Counts the number of immutable feature restrictions that are violated in the generated explanation. Measures actionability.
Redundancy — range: other
- Checks how many changed attributes could be reverted without changing the counterfactual's predicted class. Measures sparsity.
Y-NN — range: [0, 1]
- Calculates the ratio of same-class elements among the 5 nearest neighbors of each counterfactual. Measures plausibility.
Success rate (primary) — range: [0, 1]
- Indicates the ratio of samples for which a valid counterfactual was successfully found. Measures validity.
Input / output format
Input: A factual tabular instance (200 per dataset) and a pre-trained binary classifier (neural network with 32 and 16 hidden neurons, ReLU activation).
Output: A counterfactual tabular instance that flips the classifier's predicted class while respecting specified immutable feature constraints.
Scoring recipe
def evaluate(factuals, counterfactuals, classifier, immutable_features):
scores = {'L0': 0, 'L1': 0, 'L2': 0, 'L_inf': 0, 'CV': 0, 'Red': 0, 'YNN': 0, 'SR': 0}
for f, cf in zip(factuals, counterfactuals):
scores['L0'] += np.count_nonzero(f != cf)
scores['L1'] += np.sum(np.abs(f - cf))
scores['L2'] += np.sum((f - cf)**2)
scores['L_inf'] += np.max(np.abs(f - cf))
scores['CV'] += sum(1 for feat in immutable_features if f[feat] != cf[feat])
scores['Red'] += count_redundant_changes(f, cf, classifier)
scores['YNN'] += ratio_same_class_neighbors(cf, classifier, k=5)
scores['SR'] += 1 if cf is valid else 0
return {k: v / len(factuals) for k, v in scores.items()}
Common pitfalls
- Lower values are better for L0, L1, L2, L∞, Constraint violation, and Redundancy, but higher values are better for Y-NN and Success rate; mixing up optimization directions leads to incorrect conclusions.
- L1, L2, and L∞ norms measure similar proximity properties but from different mathematical perspectives; interpreting them interchangeably without considering feature distribution can be misleading.
- The CARLA benchmark framework cannot evaluate counterfactual diversity, so methods producing multiple diverse counterfactuals cannot be fully assessed on this dimension.
Evidence (verbatim from paper)
We evaluate the performance of the generated counterfactuals using several metrics, which are enumerated below. L0 norm: it measures the L0 norm between the studied sample and its counterfactual; that is, how many attributes change between them. It measures sparsity. L1 norm: it measures the Manhattan distance between the studied sample and its counterfactual, which evaluates similarity/closeness. Success rate: it indicates the ratio of samples whose counterfactuals were successfully found, which is a matter of validity of counterfactuals.
Citation
@misc{pascual2024onbmacf,
title={Overlap Number of Balls Model-Agnostic CounterFactuals (ONB-MACF): A Data-Morphology-based Counterfactual Generation Method for Trustworthy Artificial Intelligence},
author={Pascual-Triana et al. (2024)},
year={2024},
note={arXiv:2405.12326}
}
1---2name: carla-counterfactual-eval3description: Evaluates the quality and feasibility of model-agnostic counterfactual explanations generated for tabular data. It probes whether generated counterfactuals successfully flip classifier predictions while maintaining sparsity, proximity, actionability (immutable constraints), and plausibility across multiple binary classification tasks. Use when the user wants to benchmark on adult, COMPAS, Give Me Some Credit, HELOC, Irish, Saheart, Titanic, Wine, or asks about evaluating this task. Reports Success rate.4---56# carla-counterfactual-eval78> Overlap Number of Balls Model-Agnostic CounterFactuals (ONB-MACF): A Data-Morphology-based Counterfactual Generation Method for Trustworthy Artificial Intelligence — Pascual-Triana et al. (2024) (arXiv:2405.12326, 2024)910## What this evaluates1112Evaluates the quality and feasibility of model-agnostic counterfactual explanations generated for tabular data. It probes whether generated counterfactuals successfully flip classifier predictions while maintaining sparsity, proximity, actionability (immutable constraints), and plausibility across multiple binary classification tasks.1314## Datasets1516- **adult** — total 24416; splits: test (200)17- **COMPAS** — total 6172; splits: test (200)18- **Give Me Some Credit** — total 23105; splits: test (200)19- **HELOC** — total 9871; splits: test (200)20- **Irish** — total 500; splits: test (200)21- **Saheart** — total 462; splits: test (200)22- **Titanic** — total 2099; splits: test (200)23- **Wine** — total 4898; splits: test (200)2425## Metrics2627- `L0 norm` — range: other28 - Counts the number of attributes that change between the factual sample and its counterfactual. Measures sparsity.29- `L1 norm` — range: other30 - Computes the Manhattan distance between the factual sample and its counterfactual. Measures proximity/closeness.31- `L2 norm` — range: other32 - Computes the squared Euclidean distance between the factual sample and its counterfactual. Measures proximity/closeness.33- `L∞ norm` — range: other34 - Computes the maximum absolute difference across features between the factual sample and its counterfactual. Measures proximity/closeness.35- `Constraint violation` — range: other36 - Counts the number of immutable feature restrictions that are violated in the generated explanation. Measures actionability.37- `Redundancy` — range: other38 - Checks how many changed attributes could be reverted without changing the counterfactual's predicted class. Measures sparsity.39- `Y-NN` — range: [0, 1]40 - Calculates the ratio of same-class elements among the 5 nearest neighbors of each counterfactual. Measures plausibility.41- `Success rate` **(primary)** — range: [0, 1]42 - Indicates the ratio of samples for which a valid counterfactual was successfully found. Measures validity.4344## Input / output format4546**Input**: A factual tabular instance (200 per dataset) and a pre-trained binary classifier (neural network with 32 and 16 hidden neurons, ReLU activation).4748**Output**: A counterfactual tabular instance that flips the classifier's predicted class while respecting specified immutable feature constraints.4950## Scoring recipe5152```python53def evaluate(factuals, counterfactuals, classifier, immutable_features):54 scores = {'L0': 0, 'L1': 0, 'L2': 0, 'L_inf': 0, 'CV': 0, 'Red': 0, 'YNN': 0, 'SR': 0}55 for f, cf in zip(factuals, counterfactuals):56 scores['L0'] += np.count_nonzero(f != cf)57 scores['L1'] += np.sum(np.abs(f - cf))58 scores['L2'] += np.sum((f - cf)**2)59 scores['L_inf'] += np.max(np.abs(f - cf))60 scores['CV'] += sum(1 for feat in immutable_features if f[feat] != cf[feat])61 scores['Red'] += count_redundant_changes(f, cf, classifier)62 scores['YNN'] += ratio_same_class_neighbors(cf, classifier, k=5)63 scores['SR'] += 1 if cf is valid else 064 return {k: v / len(factuals) for k, v in scores.items()}65```6667## Common pitfalls6869- Lower values are better for L0, L1, L2, L∞, Constraint violation, and Redundancy, but higher values are better for Y-NN and Success rate; mixing up optimization directions leads to incorrect conclusions.70- L1, L2, and L∞ norms measure similar proximity properties but from different mathematical perspectives; interpreting them interchangeably without considering feature distribution can be misleading.71- The CARLA benchmark framework cannot evaluate counterfactual diversity, so methods producing multiple diverse counterfactuals cannot be fully assessed on this dimension.7273## Evidence (verbatim from paper)7475> We evaluate the performance of the generated counterfactuals using several metrics, which are enumerated below. L0 norm: it measures the L0 norm between the studied sample and its counterfactual; that is, how many attributes change between them. It measures sparsity. L1 norm: it measures the Manhattan distance between the studied sample and its counterfactual, which evaluates similarity/closeness. Success rate: it indicates the ratio of samples whose counterfactuals were successfully found, which is a matter of validity of counterfactuals.7677## Citation7879```bibtex80@misc{pascual2024onbmacf,81 title={Overlap Number of Balls Model-Agnostic CounterFactuals (ONB-MACF): A Data-Morphology-based Counterfactual Generation Method for Trustworthy Artificial Intelligence},82 author={Pascual-Triana et al. (2024)},83 year={2024},84 note={arXiv:2405.12326}85}86```8788- arXiv: 2405.12326