Skip to content
induwara.lk
induwara.lkMachine Learning · Metrics

Macro, Micro & Weighted F1 Score Calculator (Multiclass)

Paste a multiclass confusion matrix and get per-class precision, recall and F1 plus the three averages everyone mixes up, macro, micro and weighted, with accuracy and every step of the arithmetic shown. Matches scikit-learn.

By Induwara AshinsanaUpdated Jul 12, 2026
Multiclass F1 calculatormacro · micro · weighted
scikit-learn verified
Load an example
True class down the rows, predicted class across the columns

Rows = true class · Columns = predicted class. Edit the labels or the counts; totals update live.

Macro-F1
0.6892
Unweighted mean across classes
Weighted-F1
0.6865
Mean weighted by class support
Micro-F1
0.6818
= accuracy for single-label problems ✓
Accuracy
0.6818
15 of 22 correct · 68.18%

Averaging modes

AveragePrecisionRecallF1
Macro avg
each class counts once
0.72630.67860.6892
Weighted avg
weighted by support
0.71800.68180.6865
Micro avg
pooled TP/FP/FN
0.68180.68180.6818
Accuracy0.6818

Micro working (pooled counts)

ΣTP = 15 · ΣFP = 7 · ΣFN = 7

Micro-F1 = 2·ΣTP / (2·ΣTP + ΣFP + ΣFN) = 30 / 44 = 0.6818

ΣFP = ΣFN here (every error is one FP and one FN), so Micro-F1 equals accuracy, which is why classification_reportprints one “accuracy” row instead of a micro row.

Per-class breakdown

ClassTPFPFNPrecisionRecallF1Support
A5120.83330.71430.76927
B6520.54550.75000.63168
C4130.80000.57140.66677

Single-label multiclass only. Precision, recall and F1 use the scikit-learn definitions; a 0/0 metric is reported as 0, matching classification_report.

How it works

A multiclass model is scored from its confusion matrix, a K×K grid where C[i][j] is the number of samples whose true class is i and whose predicted class is j. The diagonal holds correct predictions. From that single grid every metric below is derived, using the definitions in scikit-learn's precision_recall_fscore_support.

For each class c the tool reads four counts straight off the matrix:

  • TP = C[c][c] (correct for c)
  • FP = column c total − TP (predicted c, truly other)
  • FN = row c total − TP (truly c, predicted other)
  • support = row c total = TP + FN (true instances of c)

Precision is TP / (TP + FP), recall is TP / (TP + FN), and the per-class F1 is their harmonic mean, 2·P·R / (P + R). When a denominator is zero, a class never predicted, or with no true samples, the metric is defined as 0, matching classification_report, so you never see a NaN.

The three averaging modes differ only in how they combine those per-class numbers, and that is exactly what trips people up:

  • Macro, the plain mean of the per-class F1 over the K classes: Macro-F1 = (ΣF1_c) / K. Every class counts once, so a poorly-handled minority class hurts as much as the majority class.
  • Weighted, the mean weighted by each class's support: Weighted-F1 = (Σ support_c · F1_c) / N. Larger classes pull the average toward their own score.
  • Micro, pool first, then divide: Micro-F1 = 2·ΣTP / (2·ΣTP + ΣFP + ΣFN). Because a single-label error is one FP and one FN at the same time, ΣFP = ΣFN, so micro-precision, micro-recall and micro-F1 all collapse to ΣTP / N, plain accuracy. That is why scikit-learn prints an “accuracy” row rather than a micro row.

The calculator surfaces the pooled ΣTP, ΣFP and ΣFN it uses for micro and the support weights it uses for weighted, so the arithmetic is auditable, and it flags when macro-F1 falls well below micro-F1, the tell-tale sign that class imbalance is hiding a weak minority class.

Worked examples

Balanced 3-class (A, B, C)

N = 22 · 15 correct

  1. Matrix rows (true→pred): A [5,2,0], B [1,6,1], C [0,3,4]
  2. A: TP 5, FP 1, FN 2 → P 0.8333, R 0.7143, F1 0.7692
  3. B: TP 6, FP 5, FN 2 → P 0.5455, R 0.7500, F1 0.6316
  4. C: TP 4, FP 1, FN 3 → P 0.8000, R 0.5714, F1 0.6667
  5. Macro-F1 = (0.7692+0.6316+0.6667)/3 = 0.6892
  6. Weighted = (7·0.7692+8·0.6316+7·0.6667)/22 = 0.6865
  7. Micro-F1 = 15/22 = 0.6818 = accuracy ✓

Imbalanced 3-class (X rare, Y majority, Z)

N = 62 · 59 correct

  1. Matrix rows (true→pred): X [1,1,0], Y [0,50,0], Z [0,2,8]
  2. X: TP 1, FP 0, FN 1 → P 1.0000, R 0.5000, F1 0.6667
  3. Y: TP 50, FP 3, FN 0 → P 0.9434, R 1.0000, F1 0.9709
  4. Z: TP 8, FP 0, FN 2 → P 1.0000, R 0.8000, F1 0.8889
  5. Macro-F1 = (0.6667+0.9709+0.8889)/3 = 0.8421
  6. Weighted = (2·0.6667+50·0.9709+10·0.8889)/62 = 0.9479
  7. Micro-F1 = 59/62 = 0.9516 = accuracy ✓
  8. Macro (0.8421) ≪ micro (0.9516): rare class X drags macro down but barely dents the pooled figure.

Edge case, a class never predicted

Binary [[0,5],[0,5]] · zero-denominator

  1. Class 1: TP 0, FP 0, FN 5 → precision denominator is 0 → P 0, so F1 0 (not NaN)
  2. Class 2: TP 5, FP 5, FN 0 → P 0.5000, R 1.0000, F1 0.6667
  3. Macro-F1 = (0 + 0.6667)/2 = 0.3333
  4. Micro-F1 = 5/10 = 0.5000 = accuracy ✓
  5. The tool reports the 0/0 class as 0 and keeps every average finite.

Frequently asked questions

Sources & references

Related tools

Comments & feedback

Spotted a bug or want an improvement? Tell us, our team reviews every comment, and good ideas get built. Comments are public and anonymous.

Found a bug, edge case, or want to suggest an improvement?

Email me at [email protected] , most fixes ship within 24 hours.