fatf.fairness.predictions.measures.counterfactual_fairness¶

fatf.fairness.predictions.measures.counterfactual_fairness(instance, protected_feature_indices, counterfactual_class=None, model=None, predictive_function=None, dataset=None, categorical_indices=None, numerical_indices=None, max_counterfactual_length=2, feature_ranges=None, distance_functions=None, step_sizes=None, default_numerical_step_size=1.0, normalise_distance=False)[source]

Checks counterfactual fairness of a prediction given a model.

This is an example of disparate treatment fairness approach, i.e. individual fairness. It checks whether there are two “similar” individuals (who only differ in the protected attributes) who are treated differently, i.e. get a different prediction.

The counterfactual fairness function is based on the object. It is based on the fatf.transparency.predictions.counterfactuals.CounterfactualExplainer object. For all the errors, warnings and exceptions please see the documentation of fatf.transparency.predictions.counterfactuals.CounterfactualExplainer object and its methods.

Parameters
instance, counterfactual_class, and normalise_distance

For the description of these parameters please see the documentation of fatf.transparency.predictions.counterfactuals.CounterfactualExplainer.explain_instance method.

protected_feature_indices, model, predictive_function, dataset, categorical_indices, numerical_indices, max_counterfactual_length, feature_ranges, distance_functions, step_sizes, and default_numerical_step_size

For the desctiption of these parameters please see the documentation of fatf.transparency.predictions.counterfactuals.CounterfactualExplainer object. The only difference is that the counterfactual_feature_indices parameter is renamed to protected_feature_indices and is required by this function.

Returns
counterfactualsnumpy.ndarray

A 2-dimensional numpy array with counterfactually unfair data points.

distancesnumpy.ndarray

A 1-dimensional numpy array with distances from the input instance to every counterfactual data point.

predictionsnumpy.ndarray

A 1-dimensional numpy array with predictions for every counterfactual data point.