holisticai.bias.metrics.correlation_diff#

holisticai.bias.metrics.correlation_diff(group_a, group_b, y_pred, y_true, q=0)[source]#

Correlation difference

This function computes the difference in correlation between predictions and targets for group_a and group_b.

If q is a vector, this function returns a vector with the respective result for each given quantile in q.

Interpretation

A value of 0 is desired. This metric ranges between -2 and 2, with -1 indicating strong bias against group_a, and +1 indicating strong bias against group_b.

Parameters

group_aarray-like

Group membership vector (binary)

group_barray-like

Group membership vector (binary)

y_predarray-like

Predictions vector (regression)

y_truenumpy array

Target vector (regression)

qfloat, array-like, optional

quantile of predictions considered, default=0.

Returns

float

correlation difference

Notes

\(CV_a - CV_b\)

Examples

>>> import numpy as np
>>> from holisticai.bias.metrics import correlation_diff
>>> group_a = np.array([1] * 50 + [0] * 50)
>>> group_b = np.array([0] * 50 + [1] * 50)
>>> y_pred = np.concatenate((np.linspace(-1, 1, 50), np.linspace(-1, 1, 50) ** 3))
>>> y_true = np.concatenate((np.linspace(-1, 1, 50), np.linspace(-1, 1, 50) ** 2))
>>> correlation_diff(group_a, group_b, y_pred, y_true, q=0)
1.0000000000000002