Confusion matrix
A confusion matrix shows how reference labels and predicted labels pair up. It reveals errors that a single accuracy score can hide.
| Class | A | B |
|---|---|---|
| A | 8 | 2 |
| B | 1 | 9 |
Intuition: count each kind of outcome
Choose an explicit class order and put each example in one cell. On this site, rows are reference classes and columns are predictions. The diagonal counts agreements. Off-diagonal cells show the direction of a confusion; swapping row and column conventions reverses that interpretation.
From counts to metrics
Let count examples with reference class and prediction . Then
For class , treat it as positive and all other classes as negative:
Recall asks what fraction of reference examples of that class were recovered. Precision asks what fraction of predictions of that class were correct. If a denominator is zero, the metric needs an explicit undefined-value convention.
Read the illustrative example
The table has 20 examples and 17 diagonal agreements, so accuracy is 0.85. For class A, recall is , while precision is . There are two A examples predicted as B, and one B example predicted as A. Those error counts need not be symmetric.
F1 combines precision and recall as when defined. Macro averaging gives each class equal weight; support-weighted averaging emphasizes more common classes. Neither removes the need to inspect per-class counts.
What this table does not establish
Counts do not explain whether the evaluation split was valid or the reference labels reliable. A matrix also loses temporal order: swapping two epochs leaves it unchanged. For sleep staging, a hypnogram and subject-level uncertainty can reveal structure that an aggregate matrix cannot.
Where you will see this
The sleep-staging page withholds evaluation exports until the research is released. Cohen's kappa uses the same count table to compare agreement with a marginal-frequency baseline.