Sub topic 12
Weighted Kappa for Ordinal Labels
Assume you know basic Python, probability, and categorical agreement. You should also understand Cohen's kappa for two annotators. This chapter focuses on labels with a natural order, such as a sentiment scale from 1 to 5 or a severity scale from low to high.
Why ordinal labels need weighted agreement
Cohen's kappa treats every disagreement as equally serious. If one annotator assigns 2 and another assigns 3, it counts as the same kind of disagreement as 1 versus 5.
That treatment is unsuitable for ordinal labels. An ordinal label is a category with a meaningful order. A one-step error is usually less serious than a four-step error.
Weighted kappa gives partial credit for near matches. It compares the observed agreement with the agreement expected by chance, while applying a penalty based on the distance between labels.
| Ratings from two annotators | Typical disagreement penalty |
|---|---|
| 3 and 3 | 0 |
| 3 and 4 | Small |
| 3 and 5 | Larger |
| 1 and 5 | Largest |
The general calculation is:
- Assign a weight to every pair of labels.
- Compute weighted observed agreement.
- Compute weighted chance agreement.
- Apply the kappa formula:
weighted kappa = (observed agreement - chance agreement)
/ (1 - chance agreement)Linear and quadratic weights
Two common weighting schemes are linear and quadratic.
- Linear weights increase the penalty in direct proportion to the distance between labels.
- Quadratic weights increase the penalty according to the square of the distance.
For labels from 1 through 5, quadratic weighting penalizes a 1-versus-5 disagreement much more than a 3-versus-4 disagreement.
| Weighting scheme | Distance 1 | Distance 2 | Distance 4 |
|---|---|---|---|
| Linear penalty | 1 | 2 | 4 |
| Quadratic penalty | 1 | 4 | 16 |
The choice should match the meaning of the task. Use linear weights when each step has roughly the same importance. Use quadratic weights when distant disagreements are especially harmful.
from sklearn.metrics import cohen_kappa_score
# Ordinal ratings on a scale from 1 (lowest) to 5 (highest)
annotator_1 = [1, 2, 3, 4, 5, 3, 2]
annotator_2 = [1, 3, 3, 5, 4, 3, 1]
unweighted = cohen_kappa_score(annotator_1, annotator_2)
linear = cohen_kappa_score(
annotator_1, annotator_2, weights="linear"
)
quadratic = cohen_kappa_score(
annotator_1, annotator_2, weights="quadratic"
)
print(f"Unweighted kappa: {unweighted:.3f}")
print(f"Linear weighted kappa: {linear:.3f}")
print(f"Quadratic weighted kappa: {quadratic:.3f}")The unweighted score ignores distance. The weighted scores recognize that most disagreements in this example are close together. Always report which weighting scheme you used because the resulting values are not interchangeable.
Interpreting the result
A high weighted kappa means the annotators agree more closely than chance, while a low value means their ratings often differ or their label distributions create little agreement beyond chance. Do not interpret a score without inspecting the rating distributions and disagreement table.
Weighted kappa can hide a systematic problem. For example, one annotator might consistently assign ratings one level higher. Report the raw agreement, the weighting scheme, the label scale, and examples of disagreements alongside the score.
Exercise
Two annotators rate severity from 1 to 5. Why might quadratic weighted kappa be more appropriate than ordinary Cohen's kappa?
Show answer
Quadratic weighted kappa gives partial credit to nearby ratings and penalizes distant ratings more heavily, while ordinary kappa treats every disagreement as equally serious.