counterfactual
from compileml.fairness import counterfactual
§11 — flip the protected attribute and see whether decisions move.
Three outcomes, reported rather than skipped, and kept distinct because they mean different things:
- status="not_named" — protected_feature is None. The audit
was not told which input, if any, is the attribute, so it has nothing to
flip. That is **not** evidence the model ignores the attribute, and the
reason says so. If a column of X matches the protected attribute
value for value, the reason names it.
- status="not_an_input" — a name was given and the artifact has no
such feature, so the model cannot be using it directly. That is the
desired outcome and appears as a positive statement.
- status="flipped" — the attribute is an input and was flipped.
Parameters#
| Name | Type | Default | Kind |
|---|---|---|---|
| artifact | — | required | positional |
| X | — | required | positional |
| protected | — | required | positional |
| protected_feature | str | None | required | positional |
| labels | — | None | keyword-only |
Returns#
dict