Sub topic 10
Where Kappa Misleads: Prevalence and Bias
Assume you know basic probability, Python lists and functions, and common NLP tasks such as text classification. This chapter focuses on Cohen's kappa for two annotators. You will learn why kappa can disagree sharply with percent agreement.
The two ingredients in kappa
Observed agreement, p_o, is the proportion of items on which the annotators chose the same label:
p_o = matching items / all items
Cohen's kappa subtracts the agreement expected from the annotators' label frequencies:
κ = (p_o - p_e) / (1 - p_e)
Here, p_e is the chance agreement calculated from the annotators' separate label proportions.
For two labels, the calculation works like this:
| Quantity | Meaning |
|---|---|
| `p_o` | Actual proportion of matching labels |
| `p_e` | Expected matching proportion from label frequencies |
| `κ` | Agreement above chance, scaled from disagreement to perfect agreement |
The correction is useful, but its result depends strongly on the label distribution.
The prevalence problem
Prevalence is how common a label is in the data. Suppose 90% of messages are truly negative. Two annotators can agree on most negative messages simply because negative is common. If they rarely use the positive label, the expected chance agreement is already high.
Consider these two confusion matrices. Rows show annotator 1, and columns show annotator 2.
| Data | Both negative | A1 negative, A2 positive | A1 positive, A2 negative | Both positive | Observed agreement | Kappa |
|---|---|---|---|---|---|---|
| Highly prevalent negative label | 900 | 50 | 50 | 0 | 0.90 | -0.05 |
| Balanced labels | 450 | 50 | 50 | 450 | 0.90 | 0.80 |
Both examples have 90% observed agreement. In the first example, both annotators mostly use the common negative label, so chance agreement is about 0.905. Kappa is slightly negative. In the second example, each label is used about equally, so chance agreement is 0.50 and kappa is much higher.
A low kappa in a highly imbalanced dataset does not automatically mean that the annotation is useless. It may indicate that the minority class needs closer examination.
The bias problem
Bias occurs when annotators use labels at different rates. For example, annotator 1 may mark 10% of messages as positive, while annotator 2 marks none as positive. They might agree on 90% of items, but the label distributions reveal a systematic difference.
Kappa can become zero in this case because the observed agreement is no better than the agreement predicted by those unequal label frequencies. Inspect the marginal totals, meaning each annotator's total count for every label, before interpreting kappa.
from collections import Counter
def agreement_report(a, b):
if len(a) != len(b) or not a:
raise ValueError("Inputs must have the same nonzero length")
n = len(a)
observed = sum(x == y for x, y in zip(a, b)) / n
counts_a = Counter(a)
counts_b = Counter(b)
labels = set(a) | set(b)
expected = sum(
counts_a[label] * counts_b[label]
for label in labels
) / n**2
kappa = (observed - expected) / (1 - expected)
return observed, expected, kappa
a1 = ["neg"] * 900 + ["neg"] * 50 + ["pos"] * 50
a2 = ["neg"] * 900 + ["pos"] * 50 + ["neg"] * 50
observed, expected, kappa = agreement_report(a1, a2)
print(f"observed={observed:.2f}")
print(f"expected={expected:.3f}")
print(f"kappa={kappa:.3f}")A safer interpretation
Do not report kappa alone. Report:
- The number of items and the label counts for each annotator.
- Percent agreement and the confusion matrix.
- Kappa and the method used to calculate it.
- The prevalence of each label.
- Examples of disagreements, especially for rare labels.
A useful report might say: “Annotators agreed on 90% of items, but negative labels made up 95% of both annotations. Kappa was low because expected chance agreement was high. Most disagreements involved the rare positive class.”
Exercise
Two annotators agree on 95 out of 100 items, but both assign the positive label to only 2 items. What should you inspect before concluding that their annotation quality is poor?
Show answer
Inspect each annotator's label counts, the confusion matrix, the kappa calculation, and the 5 disagreement examples. The dominant negative label may make chance agreement high and kappa misleading.