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 certain threshold in which case a given instance is considered to be treated unfairly. Alternatively by using the unfair_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.

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.


True if there are any counterfactually unfair instances, False otherwise.


The unfair_counterfactuals parameter is not a 2-dimensional array. The distances parameter is not a 1-dimensional array.


Either of the required input parameters were not given: unfair_counterfactuals or distances and threshold.


The threshold parameter is not a number.


The distances array is not purely numerical.