/qa-ml-models:fairlearn-fairnessfrom qa-ml-models
Uses Fairlearn to compute group-disaggregated metrics (accuracy, selection rate, TPR, FPR) and mitigate bias with ExponentiatedGradient. For pre-deployment fairness checks, bias incident triage, or compliance evidence.
Ships in qa-ml-models. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Fairlearn provides "Metrics - Tools to assess which groups are
negatively impacted and compare models across fairness and accuracy
dimensions" and "Algorithms - Techniques to mitigate unfairness"
per the Fairlearn quickstart. Two primitives: MetricFrame (group
disaggregation) + Reductions (ExponentiatedGradient,
ThresholdOptimizer).
pip install fairlearn
# OR
conda install -c conda-forge fairlearn
Per the Fairlearn quickstart.
from fairlearn.metrics import MetricFrame
from sklearn.metrics import accuracy_score
from sklearn.tree import DecisionTreeClassifier
classifier = DecisionTreeClassifier(min_samples_leaf=10, max_depth=4)
classifier.fit(X, y_true)
y_pred = classifier.predict(X)
mf = MetricFrame(
metrics=accuracy_score,
y_true=y_true,
y_pred=y_pred,
sensitive_features=sex,
)
print(mf.by_group)
print(f"Disparity (max-min): {mf.difference()}")
Per the Fairlearn quickstart. sensitive_features can be a Series
or a 2-D array for intersectional analysis (sex × race).
from fairlearn.metrics import selection_rate
sr = MetricFrame(
metrics=selection_rate,
y_true=y_true,
y_pred=y_pred,
sensitive_features=sex,
)
print(sr.by_group)
# Demographic Parity Difference (DPD)
print(f"DPD: {sr.difference()}")
DPD = max group selection rate − min group selection rate. Industry guidance often cites the 80% rule (selection rate ratio ≥ 0.8 between groups) as a soft threshold; consult legal counsel for binding thresholds in your jurisdiction.
from fairlearn.metrics import (
true_positive_rate,
false_positive_rate,
MetricFrame,
)
mf = MetricFrame(
metrics={
"TPR": true_positive_rate,
"FPR": false_positive_rate,
"selection_rate": selection_rate,
},
y_true=y_true,
y_pred=y_pred,
sensitive_features=sex,
)
print(mf.by_group)
Equalized Odds requires both TPR and FPR to be equal across groups - stricter than Demographic Parity.
from fairlearn.reductions import DemographicParity, ExponentiatedGradient
constraint = DemographicParity()
mitigator = ExponentiatedGradient(classifier, constraint)
mitigator.fit(X, y_true, sensitive_features=sex)
y_pred_mitigated = mitigator.predict(X)
Per the Fairlearn quickstart: this approach significantly reduces
selection-rate differences while maintaining accuracy. Other
constraints: EqualizedOdds, TruePositiveRateParity,
FalsePositiveRateParity.
from fairlearn.postprocessing import ThresholdOptimizer
postprocess = ThresholdOptimizer(
estimator=classifier,
constraints="demographic_parity",
prefit=True,
)
postprocess.fit(X, y_true, sensitive_features=sex)
y_pred_pp = postprocess.predict(X, sensitive_features=sex)
Per the Fairlearn postprocessing guide, Fairlearn currently supports
one postprocessing technique, ThresholdOptimizer. Cheaper than
retraining; trades model output for per-group threshold adjustment.
def assert_fairness(y_true, y_pred, sensitive, max_dpd=0.10):
sr = MetricFrame(
metrics=selection_rate,
y_true=y_true,
y_pred=y_pred,
sensitive_features=sensitive,
)
dpd = sr.difference()
if dpd > max_dpd:
raise AssertionError(
f"Demographic Parity Difference {dpd:.3f} exceeds budget {max_dpd}"
)
assert_fairness(y_true, y_pred, sex, max_dpd=0.10)
| Anti-pattern | Why it fails | Fix |
|---|---|---|
| Compute aggregate accuracy only | Hides group disparities | Always use MetricFrame (Step 2) |
| Choose Demographic Parity for all problems | DP can be inappropriate when base rates legitimately differ across groups | Match constraint to legal/ethical context: DP, EO, EOD, EOP |
| Mitigate via training data resampling alone | Doesn't generalize to new data; brittle | Use Reductions (Step 5) or post-processing (Step 6) |
| Single sensitive attribute (e.g., sex only) | Misses intersectional disparities (Black women) | Pass 2-D sensitive_features for intersection (Step 2) |
| Hard-code 80% rule globally | Not legally binding everywhere; not appropriate for all metrics | Tune max_dpd per use case + legal counsel; use waiver template if scope-exclusion needed |
What SKILL.md sets; muted values are Claude Code's defaults
7 skills in this plugin
/deepchecks-testsUse for any question or task about checking ML data before or after training, including train-test leakage, data integrity problems, and models far better offline than in production. Runs Deepchecks data integrity, train-test validation and model evaluation suites on tabular, NLP or vision data, reruns them on production samples for drift and gates CI on passed conditions./evidently-monitoringUse for any question or task about data drift or quality monitoring for a production ML model, including a fired drift alert and metrics such as precision that degrade slowly unnoticed: Evidently reports with tests for data drift, target drift and performance regression as a CI gate or scheduled job, and a playbook to pick rollback, retrain, quarantine or alert re-tuning./giskard-testsUse for any question or task about testing a trained tabular or NLP model before it ships, including robustness to small input changes, data leakage and fairness, or a pre-merge check after a feature or hyperparameter change. Runs Giskard scan and its test catalog for performance, robustness, fairness, data leakage and ethical issues, and emits suites that pass or fail in CI./model-performance-regression-gateUse when a retrained ML model is a candidate for promotion and CI must block it if it got worse. Compares held-out accuracy, F1, AUC or RMSE with the production model within a tolerance, and checks key segments with Deepchecks so a global gain cannot hide a slice regression./model-risk-evidence-matrixUse when an ML model release is up for promotion and someone must decide which fairness and explainability evidence is required, or check the evidence against the model's risk tier. Assigns a low, medium or high tier, lists required artifacts and returns promote, needs-work or block./notebook-ci-pipeline-authorUse when Jupyter notebooks must run in CI as tests, their outputs must stay stable, or a PR adding notebooks needs review. Wires papermill parameterized runs, nbval output checks, testbook unit tests, nbstripout and artifacts into GitHub Actions, plus a review checklist with a BLOCK or PASS verdict.npx claudepluginhub testland/qa --plugin qa-ml-models2 plugins ship this exact skill · first indexed Nov 12, 2026
Other plugins' skills for the same job