Binary classification metrics
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.
Implement
classification_metrics(preds: list[int], labels: list[int]) → list[float]Examples
in
[[1,0,1,0],[1,0,0,0]]out[0.75,0.5,1]What a strong answer looks like
State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
0:00 of about 22 min
solution.py
InputExpectedGot
[[1,0,1,0],[1,0,0,0]][0.75,0.5,1]not run yetsample