With more than two classes there's no single "positive" class, so precision and recall need pooling. Micro-averaging pools the counts themselves: total up true positives, false positives and false negatives across every class, then compute one precision, one recall, one F1.
For each class c, counting over all samples:
c, actually cc, actually something elsecThen precision = TP / (TP + FP), recall = TP / (TP + FN), and F1 = 2·P·R / (P + R).
Task: write micro_f1(y_true, y_pred) returning the micro-averaged F1, rounded to 4 decimal places.
0.0 if there are no true positives at all.Micro-averaging is dominated by whichever classes have the most samples — a rare class barely moves it. That's the opposite of macro-averaging, which gives every class an equal vote regardless of size. Neither is more correct; they answer different questions.