holisticai.bias.metrics.social_fairness_ratio#
- holisticai.bias.metrics.social_fairness_ratio(group_a, group_b, data, centroids)[source]#
Social Fairness Ratio
Given a centroid based clustering, this function compute the average distance to the nearest centroid for both groups. The metric is the ratio of the resulting distance for group_a to group_b.
Interpretation
A value of 1 is desired. Lower values indicate the group_a is on average closer to the respective centroids. Higher values indicate that group_a is on average further from the respective centroids.
Parameters
- group_aarray-like
Group membership vector (binary)
- group_barray-like
Group membership vector (binary)
- datamatrix-like
Data matrix of shape (num_inst, dim)
- centroidsmatrix-like
Centroids (centers) of shape (num_centroids, dim)
Returns
- float
Social Fairness Ratio
Examples
>>> import numpy as np >>> from holisticai.bias.metrics import social_fairness_ratio >>> 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]) >>> data = np.array( ... [ ... [-1, 1], ... [1, 1], ... [1, 1], ... [0, -1], ... [-1, 1], ... [-1, 1], ... [-1, 1], ... [-1, 1], ... [1, 1], ... [0, -1], ... ] ... ) >>> centroids = np.array([[-2, 1], [1, 2], [0, -2]]) >>> social_fairness_ratio(group_a, group_b, data, centroids) 1.0