# recall_score#

class usencrypt.ai.metrics.recall_score(y_true, y_pred, labels=None, pos_label=1, average='binary')#

Computes the recall score, calculated as the ratio $$\frac{\text{TP}}{(\text{TP} + \text{FN})}$$ where $$\text{TP}$$ is the number of true positives and $$\text{FN}$$ is the number of false negatives.

Parameters
• y_true (list or numpy.ndarray) – The ground-truth labels.

• y_pred (list or numpy.ndarray) – The predicted labels.

• labels (list or numpy.ndarray) – The set of labels to include when average != 'binary'. By default, all labels in y_true and y_pred are used in their order of appearance. Defaults to None.

• pos_label (str, usencrypt.cipher.String, int, or usencrypt.cipher.Int) – The class to report if average = 'binary' and the data is binary. Otherwise, this parameter is ignored. Defaults to 1.

• average ({'micro', 'macro', 'weighted', 'binary'} or None) –

This determines the type of averaging performed on the data. If None, the scores for each class are returned. Defaults to 'binary'.

• 'micro': Calculates the recall score globally by counting the total

true positives, false negatives and false positives. This is equivalent to accuracy.

• 'macro': Calculates the recall score for each class and finds their

unweighted mean.

• 'weighted': Calculates the recall score for each class and finds their

average weighted by the support (the number of instances for each label).

• 'binary': Only reports the recall score of the class denoted by

pos_label as long as y_true and y_pred are binary.

Returns

Returns the recall score of the positive class for binary classification or an array of the recall scores of each class for multi-class classification. If average is None, the recall scores for each unique class are returned in a numpy.ndarray of shape (num_unique_classes, num_unique_classes).

Return type

float, usencrypt.cipher.Float, or numpy.ndarray of float or usencrypt.cipher.Float.

Examples

For binary classification, the recall score can be computed as follows:

>>> import numpy as np
>>> import usencrypt as ue
>>> y_true = np.random.randint(0, 2, size=(10,))
>>> y_true
array([0 0 0 1 1 0 1 0 0 1])
>>> y_pred = np.random.randint(0, 2, size=(10,))
>>> y_pred
array([0 0 1 1 0 1 0 0 0 0])
>>> recall = ue.ai.metrics.recall_score(y_true, y_pred)
>>> recall
0.4


Further, setting the average parameter to None in multi-class classification results in a numpy.ndarray containing the recall scores for each unique class:

>>> import numpy as np
>>> import usencrypt as ue
>>> y_true = np.random.randint(0, 2, size=(10,))
>>> y_true
array([0 2 0 1 2 0 2 1 2 1])
>>> y_pred = np.random.randint(0, 3, size=(10,))
>>> y_pred
array([0 2 1 2 1 2 0 2 2 1])
>>> recall = ue.ai.metrics.recall_score(y_true, y_pred, average = None)
>>> recall
array([0.3333333333333333 0.5 0.3333333333333333])