# interpretml/DiCE

Generate Diverse Counterfactual Explanations for any machine learning model.

Repository: https://github.com/interpretml/DiCE
Canonical: https://ross.abutalabs.com/products/dice
Homepage: https://interpretml.github.io/DiCE/
Language: Python
License: MIT
License Family: permissive
Topics: counterfactual-explanations, explainable-ml, xai, interpretable-machine-learning, deep-learning, machine-learning, explainable-ai
Last push: 2025-07-13T17:34:53+00:00

## Health v2 (maintenance only)
Score: 37/100 (v2, computed 2026-09-02T17:46:02.011165+00:00)
- activity 31, release rhythm 8, longevity 100
- inputs: {"age_days": 2680, "days_push": 416, "days_rel": 416, "gap_med": null, "n_releases_24m": 1}
- flags: none
- formula: round(0.45*activity + 0.35*rhythm + 0.20*longevity); archived -> min(score, 10)

## Adoption (not part of the score)
Stars 1525, forks 235 (observed 2026-08-28T04:04:58.309002+00:00)

## What it is
DiCE is a Python library that generates diverse counterfactual explanations for any machine learning model, showing feature-perturbed versions of an input that would flip the model's decision. It supports model-agnostic methods (random sampling, genetic search, KD-tree) as well as gradient-based methods for TensorFlow and PyTorch models.

## Use cases
- explain why a loan application was rejected and what would change the outcome
- generate counterfactual examples for a scikit-learn classifier
- produce what-if explanations for a deep learning model
- audit model decisions in finance or healthcare with actionable explanations
- generate diverse counterfactuals for a black-box ML model
- complement SHAP or LIME explanations with counterfactuals

## When to choose
- you need actionable 'what-if' explanations for model predictions
- you want model-agnostic counterfactual generation across sklearn, TensorFlow, or PyTorch models
- you need multiple diverse counterfactuals rather than a single nearest example
- you are doing explainable AI research or building XAI pipelines in Python

## When to avoid
- you need feature-importance or attribution explanations rather than counterfactuals
- you work outside Python or need a GUI-based explanation tool
- your model is a simple linear model where counterfactuals add little value
- you need real-time explanations with strict latency constraints

## Facets
- artifact type: library
- maturity: active
- function: machine-learning, nlp
- domain: machine-learning, artificial-intelligence, data-science
- platform: python
- tags: counterfactual-explanations, explainable-ai, xai, interpretable-ml, model-agnostic, what-if-explanations

## Member repositories
- interpretml/DiCE (main) score 37

## Provenance
- Observed fields: from GitHub, fetched 2026-08-28T04:04:58.309002+00:00.
- Health v2: computed from the inputs above; adoption is never an input.
- Inferred fields (summary, facets, guidance): AI-extracted, prompt v1, taxonomy v1, on 2026-08-30T04:31:39.687445+00:00, confidence not recorded.
  - readme: https://github.com/interpretml/DiCE (fetched 2026-08-28T04:04:58.309002+00:00, sha 2210293cf887)
  - homepage: https://interpretml.github.io/DiCE/ (fetched 2026-08-29T11:34:19.676398+00:00, sha 0c8cb07d8ba5)
  - site_page: http://interpret.ml/DiCE/readme.html (fetched 2026-08-29T11:34:19.685831+00:00, sha 1986bc6c04f5)
  - site_page: http://interpret.ml/DiCE/notebooks/DiCE_model_agnostic_CFs.html (fetched 2026-08-29T11:34:19.688211+00:00, sha 3561e6380a19)
- Data as of 2026-08-30T08:39:29.467469+00:00.
