Sub topic 11
Fleiss' kappa for more than two annotators
This chapter assumes you know Cohen's kappa for two annotators: observed agreement, chance agreement, and the formula (observed - chance) / (1 - chance). It also assumes basic Python and a pilot round that produced labels. Here you extend the same idea to three or more annotators.
Why Cohen's kappa is not enough
Cohen's kappa compares exactly two annotators. Real projects usually use three or five, because a majority vote gives more reliable gold labels. You could average Cohen's kappa over every pair, but Fleiss' kappa gives one number for the whole group and does not require a pairwise matrix.
Fleiss' kappa keeps the same logic as Cohen's kappa. It compares how much the annotators agree with how much they would agree by chance. The difference is how both quantities are computed from the group.
The assumptions
Fleiss' kappa works under these conditions:
- Every item is labeled by the same number of annotators, called n.
- The labels are nominal categories with no order.
- Annotators are interchangeable. The measure does not track who gave which label.
- Annotators may differ between items. Item 1 can be labeled by A, B, C and item 2 by A, D, E, as long as each gets n labels. This is common with crowdsourcing.
If these conditions fail, use another measure. Missing labels or ordinal scales point to Krippendorff's alpha or weighted kappa, covered in later chapters.
From labels to a count table
The input is not a list of labels per annotator. It is a table with one row per item and one column per category. Each cell holds how many annotators chose that category for that item.
Take six items, three annotators, and categories 0, 1 and 2:
| Item | Labels | Count of 0 | Count of 1 | Count of 2 |
|---|---|---|---|---|
| 1 | 0, 0, 0 | 3 | 0 | 0 |
| 2 | 0, 1, 0 | 2 | 1 | 0 |
| 3 | 1, 1, 1 | 0 | 3 | 0 |
| 4 | 2, 2, 1 | 0 | 1 | 2 |
| 5 | 0, 0, 0 | 3 | 0 | 0 |
| 6 | 1, 1, 2 | 0 | 2 | 1 |
Each row sums to n = 3. Once you have this table, the identity of each annotator is gone.
Computing observed agreement
For each item, Fleiss' kappa asks: if I pick two of the n annotators at random, how likely is it that they agree? For item i with category counts n_ij, the answer is:
Pi = (sum over j of nij² - n) / (n(n - 1))
The item's score is 1 when all annotators agree. It is 0 when no two annotators agree. The overall observed agreement P̄ is the mean of P_i over all items.
For the table above, the six P_i values are 1, 1/3, 1, 1/3, 1 and 1/3. Their mean is P̄ = 4/6 ≈ 0.667.
Computing chance agreement
Chance agreement uses the overall share of each category across all labels. Let p_j be the total count of category j divided by the total number of labels (items × n). Then:
Pe = sum over j of pj²
In the example there are 18 labels. Category 0 has 8, category 1 has 7 and category 2 has 3. So p = 0.444, 0.389 and 0.167, and P_e ≈ 0.377.
Fleiss' kappa is then:
κ = (P̄ - Pe) / (1 - Pe) = (0.667 - 0.377) / (1 - 0.377) ≈ 0.465
The calculation has three stages:
Implementation from scratch
This function takes the count table directly and returns kappa:
def fleiss_kappa(table):
n_items = len(table)
n = sum(table[0])
if any(sum(row) != n for row in table):
raise ValueError("Every item needs the same number of ratings")
k = len(table[0])
p_j = [sum(row[j] for row in table) / (n_items * n) for j in range(k)]
p_i = [(sum(c * c for c in row) - n) / (n * (n - 1)) for row in table]
p_bar = sum(p_i) / n_items
p_e = sum(p * p for p in p_j)
if p_e == 1:
return float("nan") # all labels in one category: kappa is undefined
return (p_bar - p_e) / (1 - p_e)
counts = [
[3, 0, 0],
[2, 1, 0],
[0, 3, 0],
[0, 1, 2],
[3, 0, 0],
[0, 2, 1],
]
print(round(fleiss_kappa(counts), 3))The output is 0.465. The check for equal row sums enforces the main assumption. The p_e == 1 guard handles the case where every annotator uses a single category for every item. The formula would divide by zero there.
Using statsmodels
In practice you will often use a library. The statsmodels function aggregate_raters builds the count table from a items-by-annotators array of integer codes:
from statsmodels.stats.inter_rater import aggregate_raters, fleiss_kappa
# Rows are items, columns are annotators, values are integer label codes
ratings = [
[0, 0, 0],
[0, 1, 0],
[1, 1, 1],
[2, 2, 1],
[0, 0, 0],
[1, 1, 2],
]
table, categories = aggregate_raters(ratings)
print(table)
print(categories)
print(fleiss_kappa(table, method="fleiss"))The result matches the hand calculation, about 0.465. Print table and categories once to confirm that the columns are in the order you expect. If your labels are strings, map them to integers first.
Reading the result
The same rough scales used for Cohen's kappa apply. Treat them as conventions, not rules. A value of 0.465 is moderate. It suggests the guidelines leave real ambiguity, and it is too low to trust single labels without adjudication.
Three cautions matter more with several annotators:
- Prevalence still distorts the score. If 90% of labels fall in one category, P_e is high and kappa can be low even when annotators rarely disagree. Report the category distribution next to kappa.
- One overall number hides structure. Kappa may be driven by one confusing category pair. Compute a one-versus-rest kappa for each category, or inspect the pairwise confusion matrices, to find the source.
- Annotator quality is invisible. Fleiss' kappa cannot tell you that one annotator is careless. If kappa is low, compute pairwise Cohen's kappa and look for an annotator who disagrees with everyone.
Fleiss' kappa also differs slightly from Cohen's in how it models chance. Cohen's uses each annotator's own label distribution. Fleiss' pools all annotators into one distribution. Because of that, the two can differ even for n = 2, and Fleiss' kappa ignores systematic differences in how individual annotators use the labels.
Choosing a measure
| Situation | Measure |
|---|---|
| Two annotators, nominal labels | Cohen's kappa |
| Three or more annotators, same count per item, nominal labels | Fleiss' kappa |
| Ordinal ratings | Weighted kappa or Krippendorff's alpha |
| Missing labels or varying annotators per item | Krippendorff's alpha |
| Entity spans | Span-level F1 between annotators |
Common mistakes
- Passing the annotators-by-items matrix to
fleiss_kappainstead of the count table. The function expects counts and will not warn you if the numbers look plausible. - Dropping items that some annotators skipped without checking that the rest still have equal counts.
- Reporting kappa without the number of items, number of annotators and label distribution. A kappa from 20 items has a wide uncertainty range, so a bootstrap confidence interval is worth computing.
Exercise
Four items are each labeled by three annotators using two categories. The count table is [[3, 0], [0, 3], [2, 1], [1, 2]]. Compute Fleiss' kappa.
Show answer
Per-item agreement is Pi = (sum of squared counts - 3) / 6, giving 1, 1, 1/3 and 1/3. The mean is P̄ = 0.667. Each category has 6 of the 12 labels, so p = 0.5 for both and Pe = 0.25 + 0.25 = 0.5. Kappa = (0.667 - 0.5) / (1 - 0.5) ≈ 0.333, which is fair agreement.