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
distances
to the counterfactual examples and see whether there are any that exceed a certainthreshold
in which case a given instance is considered to be treated unfairly. Alternatively by using theunfair_counterfactuals
array 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
True
if there are any counterfactually unfair instances,False
otherwise.
- Raises
- IncorrectShapeError
The
unfair_counterfactuals
parameter is not a 2-dimensional array. Thedistances
parameter is not a 1-dimensional array.- RuntimeError
Either of the required input parameters were not given:
unfair_counterfactuals
ordistances
andthreshold
.- TypeError
The
threshold
parameter is not a number.- ValueError
The
distances
array is not purely numerical.