holisticai.bias.metrics.exposure_l1#

holisticai.bias.metrics.exposure_l1(group_a, group_b, mat_pred, top=None, thresh=0.5, normalize=False)[source]#

Exposure Total Variation

This function computes the total variation norm between the group_a exposure distribution to the group_b exposure distribution.

Interpretation

A total variation divergence of 0 is desired, which occurs when the distributions are equal. The maximum value is 1 indicating the distributions are very far apart.

Parameters

group_aarray-like

Group membership vector.

group_barray-like

Group membership vector.

mat_predmatrix-like

Matrix with shape (num_users, num_items). A recommender score (binary or soft pred) for each user,item interaction.

top (optional)int

If not None, the number of items that are shown to each user.

thresh (optional)float

Threshold indicating value at which a given item is shown to user (if top is None).

normalize (optional)bool

If True, normalises the data matrix to [0,1] range.

Returns

float

Exposure Total Variation

References

Examples

>>> import numpy as np
>>> from holisticai.bias.metrics import exposure_l1
>>> group_a = np.array([1, 1, 1, 1, 0, 0, 0, 0, 0, 0])
>>> group_b = np.array([0, 0, 0, 0, 1, 1, 1, 1, 1, 1])
>>> mat_pred = np.array([[0.9, 0.8, 0.4, 0.2],
                        [0.7, 0.9, 0.1, 0.7],
                        [0.3, 0.2, 0.3, 0.3],
                        [0.2, 0.1, 0.7, 0.8],
                        [0.8, 0.7, 0.9, 0.1],
                        [1. , 0.9, 0.3, 0.6],
                        [0.8, 0.9, 0.1, 0.1],
                        [0.2, 0.3, 0.1, 0.5],
                        [0.1, 0.2, 0.7, 0.7],
                        [0.2, 0.7, 0.1, 0.2]])
>>> exposure_l1(group_a, group_b, mat_pred, top=1, thresh=None, normalize=False)
0.25