#52 · Machine Learning · Easy
⊣ Solve on deep-ml.comImplement the recall metric for binary classification. Recall (also known as sensitivity or true positive rate) is the ratio of true positives to the total number of actual positives.
import numpy as np
def recall(y_true, y_pred):
y_true = np.array(y_true)
y_pred = np.array(y_pred)
true_positives = np.sum((y_pred == 1) & (y_true == 1))
actual_positives = np.sum(y_true == 1)
if actual_positives == 0:
return 0.0
return float(true_positives / actual_positives)