fairlearn.metrics.make_derived_metric#
- fairlearn.metrics.make_derived_metric(*, metric, transform, sample_param_names=['sample_weight'])[source]#
Create a scalar returning metric function based on aggregation of a disaggregated metric.
Many higher order machine learning operations (such as hyperparameter tuning) make use of functions which return scalar metrics. We can create such a function for our disaggregated metrics with this function.
This function takes a metric function, a string to specify the desired aggregation transform (matching the methods
MetricFrame.group_min()
,MetricFrame.group_max()
,MetricFrame.difference()
andMetricFrame.ratio()
), and a list of parameter names to treat as sample parameters.The result is a callable object which has the same signature as the original function, with a
sensitive_features=
parameter added. If the chosen aggregation transform accepts parameters (currently onlymethod=
is supported), these can also be given when invoking the callable object. The result of this function is identical to creating aMetricFrame
object, and then calling the method specified by thetransform=
argument (with themethod=
argument, if required).See the Defining custom fairness metrics section in the User Guide for more details. A sample notebook is also available.
- Return type:
- Parameters:
- metriccallable
The metric function from which the new function should be derived
- transformstr
Selects the transformation aggregation the resultant function should use. The list of possible options is: [‘difference’, ‘group_min’, ‘group_max’, ‘ratio’].
- sample_param_namesList[str]
A list of parameters names of the underlying
metric
which should be treated as sample parameters (i.e. the same leading dimension as they_true
andy_pred
parameters). This defaults to a list with a single entry ofsample_weight
(as used by many SciKit-Learn metrics). IfNone
or an empty list is supplied, then no parameters will be treated as sample parameters.
- Returns:
- callable
Function with the same signature as the
metric
but with additionalsensitive_features=
andmethod=
arguments, to enable the required computation