Fleiss' Kappa
Background
Fleiss' kappa extends Cohen's kappa to settings where each item is rated by multiple raters (typically 3+). It measures inter-rater agreement after correcting for chance, returning a single scalar in where 1 = perfect agreement, 0 = chance-level, negative = systematic disagreement. Standard metric for RLHF data-quality QA and human-evaluation pipelines.
Problem statement
Implement fleiss_kappa(ratings) where ratings is shape with ratings[i, k] = number of raters who assigned item to category . The total per row must be constant (equal raters per item). Compute:
where is the per-item rater count and .
Input
ratings—np.ndarrayshape of non-negative integer counts. Each row sums to the same total (the number of raters).
Output
Returns a Python float, the Fleiss kappa.
Examples
Example 1 — perfect agreement
Input: ratings = [[3,0], [0,3], [3,0]] # 3 raters, 2 categories, all agree per item
Output: 1.0
Example 2 — chance-level agreement
Input: ratings drawn from uniform multinomial
Output: ≈ 0.0
Constraints
- Rows must sum to the same value (equal raters per item). ValueError otherwise.
- Need raters per item.
- If (only one category has any votes), return .
Notes
- Interpretation. is typically called "substantial agreement"; "almost perfect". Below means the labelling task / guidelines need work.
- vs Cohen. Cohen's kappa needs exactly 2 raters; Fleiss handles any number .
▶ Run executes the 3 visible sample tests below in your browser. Submit runs the full suite — including hidden tests — on the server for an official verdict.
- •Reference example: perfect agreement returns 1.0
- •Example: four items, two categories, mixed agreement
- •Sample: three categories, partial agreement