fatf.utils.data.tools.apply_to_column_grouping¶
-
fatf.utils.data.tools.apply_to_column_grouping(labels: numpy.ndarray, predictions: numpy.ndarray, row_grouping: List[List[int]], fnc: Callable[[numpy.ndarray, numpy.ndarray], float]) → List[float][source]¶ Applies a function to the specified groups of labels and predictions.
This functions allows to apply a metric for a particular data grouping. The two main applications are group-based fairness and performance evaluation.
- Parameters
- labelsnumpy.ndarray
A ground truth numpy array.
- predictionsnumpy.ndarray
A predictions numpy array.
- row_groupingList[List[integer]]
A list of lists representing row indices of the ground truth and prediction arrays resulting in their grouping.
- fncCallable[[numpy.ndarray, numpy.ndarray], number]
A function (metric) that will be applied to all of the groups defined by the
row_groupingparameter.
- Returns
- appliedList[numbers]
A list with the
fncfunction result for every group defined by therow_groupingparameter.
- Raises
- AttributeError
The
fncparameter does not require two input parameters.- IncorrectShapeError
The
labelsorpredictionsparameter is not a 1-dimensional numpy array. Thelabelsandpredictionsarrays are not of the same length.- TypeError
The
row_groupingparameter is not a list. One of the elements of therow_groupingis not a list. Some of the elements in the inner list of therow_groupinglist are not integers. Thefncparameter is not a callable (function).- ValueError
The
row_groupingparameter is an empty list. Some of the values in therow_groupinglist are duplicated.