fairlearn.metrics.true_positive_rate#

fairlearn.metrics.true_positive_rate(y_true, y_pred, sample_weight=None, pos_label=None)[source]#

Calculate the true positive rate (also called sensitivity, recall, or hit rate).

Read more in the User Guide.

Added in version 0.4.6.

Parameters:
  • y_true (array_like) – The list of true values

  • y_pred (array_like) – The list of predicted values

  • sample_weight (array_like, optional) – A list of weights to apply to each sample. By default all samples are weighted equally

  • pos_label (scalar, optional) – The value to treat as the ‘positive’ label in the samples. If None (the default), the labels must be drawn from {0, 1} or {-1, 1}, and 1 is used as the positive label. For other binary labels, specify pos_label explicitly.

Return type:

float

Returns:

The true positive rate for the data

Examples

The default positive label remains 1 for an all-zero group:

>>> from fairlearn.metrics import true_positive_rate
>>> float(true_positive_rate([0, 0], [0, 0]))
0.0

Other binary labels need an explicit positive label:

>>> float(true_positive_rate(["no", "yes"], ["no", "yes"], pos_label="yes"))
1.0