Binary classifier metrics
Your task
You are evaluating a binary classifier. Given two equal-length lists, y_true (the ground-truth labels, each 0 or 1) and y_pred (the predicted labels, each 0 or 1), compute precision, recall, and F1 score for the positive class (label 1). Precision = TP / (TP + FP), recall = TP / (TP + FN), and F1 = 2PR / (P+R). If any denominator is zero, treat that metric as 0.0. Return the three values as a list [precision, recall, f1], each rounded to 4 decimal places. Lists are non-empty and have length up to 10^5.
Examples
prf1(y_true: list[int], y_pred: list[int]) -> list[float]Example 1
Input
prf1([1, 0, 1, 1, 0], [1, 0, 0, 1, 1])Output
[0.6667, 0.6667, 0.6667]