Question
Given y_true and y_pred (equal-length lists of integer class labels in 0..k-1) and the number of classes k, compute the per-class precision and recall from the multiclass confusion matrix. For class c, precision = TP_c / (TP_c + FP_c) and recall = TP_c / (TP_c + FN_c), where TP_c is the count of samples with true=c and pred=c, FP_c is true!=c but pred=c, and FN_c is true=c but pred!=c. A zero denominator yields 0.0 for that metric. Return a list of k pairs [precision, recall] for classes 0..k-1, each value rounded to 4 decimals.
per_class_metrics(y_true: list[int], y_pred: list[int], k: int) → list[list[float]][[0,1,2,0,1],[0,1,1,0,1],3]out[[1,1],[0.6667,1],[0,0]]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.
Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.