aif360.sklearn.utils.check_groups

aif360.sklearn.utils.check_groups(arr, prot_attr, ensure_binary=False)[source]

Get groups from the index of arr.

If there are multiple protected attributes provided, the index is flattened to be a 1-D Index of tuples. If ensure_binary is True, raises a ValueError if there are not exactly two unique groups. Also checks that all provided protected attributes are in the index.

Parameters:
  • arr (array-like) – Either a Pandas object containing protected attribute information in the index or array-like with explicit protected attribute array(s) for prot_attr.

  • prot_attr (label or array-like or list of labels/arrays) – Protected attribute(s). If contains labels, arr must include these in its index. If None, all protected attributes in arr.index are used. Can also be 1D array-like of the same length as arr or a list of a combination of such arrays and labels in which case, arr may not necessarily be a Pandas type.

  • ensure_binary (bool) – Raise an error if the resultant groups are not binary.

Returns:

tuple

  • groups (pandas.Index) – Label (or tuple of labels) of protected attribute for each sample in arr.

  • prot_attr (FrozenList) – Modified input. If input is a single label, returns single-item list. If input is None returns list of all protected attributes.