Sub topic 11
Fleiss' Kappa for More Than Two Annotators
This chapter assumes that you know basic Python, lists, dictionaries, and functions. You should also know common NLP tasks such as text classification and named entity recognition, plus basic probability.
Fleiss' kappa measures agreement among several annotators who label the same set of items. It is useful for categorical labels such as positive, negative, and neutral. Unlike Cohen's kappa, which compares exactly two annotators, Fleiss' kappa can compare three or more.
The working model
Fleiss' kappa assumes that every item receives the same number of ratings. Each rating must use one category from a fixed label set.
The calculation has three stages:
- Measure the agreement among annotators for each item.
- Measure the agreement expected from the overall label frequencies.
- Compare the two values.
For item i, let nᵢⱼ be the number of annotators who selected category j. If an item has N ratings, its agreement is:
Pᵢ = [sum of nᵢⱼ(nᵢⱼ - 1)] / [N(N - 1)]
The overall observed agreement is the average of all Pᵢ values.
For each category j, calculate its overall proportion:
pⱼ = number of ratings with category j / total number of ratings
The chance agreement is:
Pₑ = sum of pⱼ²
Finally:
kappa = (observed agreement - chance agreement) / (1 - chance agreement)
A small example
Suppose three annotators label six messages. The count table below summarizes their choices for each message.
| Item | Positive | Neutral | Negative | Agreement Pᵢ |
|---|---|---|---|---|
| 1 | 3 | 0 | 0 | 1.00 |
| 2 | 2 | 1 | 0 | 0.33 |
| 3 | 0 | 3 | 0 | 1.00 |
| 4 | 0 | 1 | 2 | 0.33 |
| 5 | 3 | 0 | 0 | 1.00 |
| 6 | 0 | 2 | 1 | 0.33 |
The observed agreement is about 0.667. The category frequencies produce chance agreement of about 0.377. Therefore, Fleiss' kappa is about 0.465.
The observed agreement is easier to explain than the kappa value. It says that annotators agreed on about two-thirds of within-item annotator pairs. Kappa discounts the agreement that could result from frequently choosing the same categories.
Computing it in Python
The statsmodels package accepts a table containing one row per item and one column per annotator. Values are integer category codes.
from statsmodels.stats.inter_rater import aggregate_raters, fleiss_kappa
ratings = [
[0, 0, 0],
[0, 1, 0],
[1, 1, 1],
[2, 2, 1],
[0, 0, 0],
[1, 1, 2],
]
table, categories = aggregate_raters(ratings)
kappa = fleiss_kappa(table, method="fleiss")
print(f"Fleiss' kappa: {kappa:.3f}")The integer codes have no numeric meaning. They only identify categories. Keep a separate mapping, such as 0 = positive, 1 = neutral, and 2 = negative.
Interpreting the result
Kappa ranges from negative values to 1. A value of 1 means complete agreement. A value near 0 means agreement is close to the level expected from category frequencies. Negative values indicate less agreement than expected by chance.
These values are guidelines, not universal thresholds:
- below 0.20: weak agreement
- 0.20 to 0.40: limited agreement
- 0.40 to 0.60: moderate agreement
- 0.60 to 0.80: substantial agreement
- above 0.80: strong agreement
Always inspect the label frequencies and the individual disagreements. A rare category or an unclear guideline can make the overall score misleading.
Exercise
Three annotators label one item as positive, positive, and neutral. What is the item's agreement Pᵢ?
Show answer
There are two matching annotator pairs out of six ordered pairs, so Pᵢ = 2 / 6 = 0.333.