fatf.fairness.predictions.measures.counterfactual_fairness_check¶
-
fatf.fairness.predictions.measures.counterfactual_fairness_check(unfair_counterfactuals: Optional[numpy.ndarray] = None, distances: Optional[numpy.ndarray] = None, threshold: Optional[float] = None) → bool[source]¶ Checks for counterfactual fairness using a counterfactual fairness arrays.
There are two different approaches to evaluate counterfactual fairness. The first one is to take the
distancesto the counterfactual examples and see whether there are any that exceed a certainthresholdin which case a given instance is considered to be treated unfairly. Alternatively by using theunfair_counterfactualsarray this function checks whether there are any unfair counterfactual instances. In case all the input parameters are given the distance-based approach takes the precedence.- Parameters
- unfair_counterfactualsnumpy.ndarray, optional (default=None)
A 2-dimensional numpy array with counterfactual examples that expose unfairness of a prediction.
- distancesnumpy.ndarray, optional (default=None)
A 1-dimensional numpy array with .
- thresholdnumber, optional (default=None)
A numerical threshold above which a counterfactual instance is too far, therefore it is considered to be an exemplar of individual unfairness.
- Returns
- counterfactually_unfairboolean
Trueif there are any counterfactually unfair instances,Falseotherwise.
- Raises
- IncorrectShapeError
The
unfair_counterfactualsparameter is not a 2-dimensional array. Thedistancesparameter is not a 1-dimensional array.- RuntimeError
Either of the required input parameters were not given:
unfair_counterfactualsordistancesandthreshold.- TypeError
The
thresholdparameter is not a number.- ValueError
The
distancesarray is not purely numerical.