# Perturbation SHAP - ICML 2025

Understanding machine learning model decisions in vision tasks is essential for transparency and trust. This repository introduces two major contributions to the field of explainability in computer vision:

1. **Mean-Distance Perturbation (MDP):** A deterministic perturbation method that improves feature exclusion accuracy by replacing image regions with maximally distant colors in RGB or grayscale space. This ensures fidelity to SHAP axioms and enhances interpretability.
2. **SHAPEval Dataset:** A benchmark dataset with ground truth Shapley values to rigorously evaluate explainability methods for vision models.

## Perturbation Method - Mean-Distance Perturbation (MDP)

MDP is implemented in the SHAP library for feature attribution in vision models. Unlike traditional perturbation strategies such as Gaussian blurring, inpainting, or uniform color replacement, MDP replaces image regions with maximally distant colors. This deterministic approach ensures accurate feature exclusion and aligns with SHAP axioms.

**Implementation Path:**
`lib64/python3.10/site-packages/shap/maskers/_image.py`



## SHAPEval Dataset
SHAPEval is a novel dataset that provides ground truth Shapley values, allowing for rigorous and consistent evaluation of explainability methods in computer vision tasks.

### Features:
- Designed specifically for evaluating perturbation strategies and explainers.
- Ground truth Shapley values for standardized comparisons.

**Generation Code:** Located in `data_generator`

**Dataset Files:**
- **Data T:** Available in the `data` directory.
- **Data L:** Available in the `data` directory.


## Evaluation
We evaluate perturbation strategies and compare explainers using SHAPEval. MDP consistently outperforms existing strategies, such as Gaussian blurring, inpainting, and uniform color replacement, across multiple metrics on the SHAPEval dataset. Evaluation scripts can be found in the `app` directory.


## Example

### MovilNetV2
![MobilNetV2](figs/results/mobilnet.png)


### ResNet50
![ResNet50](figs/results/resnet.png)


### Other
for more see 'figs' and 'examples


## Getting Started
### Prerequisites
Required dependencies (see `requirements.txt`)

### Installation
1. Clone this repository:
   ```bash
   git clone https://github.com/yourusername/perturbation-shap.git
   cd perturbation-shap