aif360.sklearn.metrics.difference

aif360.sklearn.metrics.difference(func, y_true, y_pred=None, prot_attr=None, priv_group=1, sample_weight=None, **kwargs)[source]

Compute the difference between unprivileged and privileged subsets for an arbitrary metric.

Note: The optimal value of a difference is 0. To make it a scorer, one must take the absolute value and set greater_is_better to False.

Unprivileged group is taken to be the inverse of the privileged group.

Parameters:
  • func (function) – A metric function from sklearn.metrics or aif360.sklearn.metrics.

  • y_true (pandas.Series) – Outcome vector with protected attributes as index.

  • y_pred (array-like, optional) – Estimated outcomes.

  • prot_attr (array-like, keyword-only) – Protected attribute(s). If None, all protected attributes in y are used.

  • priv_group (scalar, optional) – The label of the privileged group.

  • sample_weight (array-like, optional) – Sample weights passed through to func.

  • **kwargs – Additional keyword args to be passed through to func.

Returns:

scalar – Difference in metric value for unprivileged and privileged groups.

Examples

>>> X, y = fetch_german(numeric_only=True)
>>> y_pred = LogisticRegression().fit(X, y).predict(X)
>>> difference(precision_score, y, y_pred, prot_attr='sex',
... priv_group='male')
-0.06955430006277463