Binary classification metrics

Write codeMedium22 minMeta style

Your task

Given equal-length lists of predicted and true binary labels (0 or 1), compute accuracy, precision, and recall for the positive class (1), returned as a list [accuracy, precision, recall]. Accuracy = correct / total. Precision = TP / (TP + FP); if there are no predicted positives, precision is 0.0. Recall = TP / (TP + FN); if there are no actual positives, recall is 0.0. Inputs are non-empty. Round each metric to 4 decimal places.

Examples

classification_metrics(preds: list[int], labels: list[int]) -> list[float]
Example 1
Inputclassification_metrics([1, 0, 1, 0], [1, 0, 0, 0])
Output[0.75, 0.5, 1]