Compute accuracy, precision, recall, and F1 for single-label classification. For each class c, let TPc count correct predictions of c, FPc count predictions of c whose true label differs, and FNc count occurrences of c predicted as another class.
Pc=TPc+FPcTPc Rc=TPc+FNcTPc F1,c=Pc+Rc2PcRcUse micro to aggregate class counts before computing metrics, macro to average class metrics equally, weighted to average them by true-label support, and binary to report the class selected by pos_label. A zero denominator contributes 0.0. Return accuracy, precision, recall, and f1 in a dictionary, with every value rounded to six decimals.
Input: y_true = [0, 1, 2, 2], y_pred = [0, 1, 0, 2], average = "micro", pos_label = 1
Output: {"accuracy": 0.75, "precision": 0.75, "recall": 0.75, "f1": 0.75}
Explanation: Three of four labels are correct; for single-label micro averaging, precision, recall, and F1 also equal 0.75.
Input: y_true = [0, 1, 2, 2], y_pred = [0, 1, 0, 2], average = "macro", pos_label = 1
Output: {"accuracy": 0.75, "precision": 0.833333, "recall": 0.833333, "f1": 0.777778}
Use np.unique(np.concatenate([y_true, y_pred])) to collect every observed class.
For each class, boolean masks can count true positives, false positives, and false negatives.
Use the true-label count of each class as its weight for weighted averaging.
Sign in to take notes on this problem
Accepts: array
Accepts: array
Accepts: string
Accepts: number
Compute accuracy, precision, recall, and F1 for single-label classification. For each class c, let TPc count correct predictions of c, FPc count predictions of c whose true label differs, and FNc count occurrences of c predicted as another class.
Pc=TPc+FPcTPc Rc=TPc+FNcTPc F1,c=Pc+Rc2PcRcUse micro to aggregate class counts before computing metrics, macro to average class metrics equally, weighted to average them by true-label support, and binary to report the class selected by pos_label. A zero denominator contributes 0.0. Return accuracy, precision, recall, and f1 in a dictionary, with every value rounded to six decimals.
Input: y_true = [0, 1, 2, 2], y_pred = [0, 1, 0, 2], average = "micro", pos_label = 1
Output: {"accuracy": 0.75, "precision": 0.75, "recall": 0.75, "f1": 0.75}
Explanation: Three of four labels are correct; for single-label micro averaging, precision, recall, and F1 also equal 0.75.
Input: y_true = [0, 1, 2, 2], y_pred = [0, 1, 0, 2], average = "macro", pos_label = 1
Output: {"accuracy": 0.75, "precision": 0.833333, "recall": 0.833333, "f1": 0.777778}
Use np.unique(np.concatenate([y_true, y_pred])) to collect every observed class.
For each class, boolean masks can count true positives, false positives, and false negatives.
Use the true-label count of each class as its weight for weighted averaging.
Sign in to take notes on this problem
Accepts: array
Accepts: array
Accepts: string
Accepts: number