Annotator agreement
Assess consistency between two human labelers assigning binary or multiclass categories.
Scikit-Learn · Function
Computes Cohen’s kappa, a chance-adjusted measure of agreement between two classification labelings. It supports optional ordinal disagreement weights, sample weights, explicit labels, and an undefined-result replacement value.
The function compares two label assignments sample by sample. It calculates observed agreement and adjusts it for the agreement expected from the label distributions; optional weights make disagreements ordinal, and sample weights change each observation's contribution.
sklearn.metrics.cohen_kappa_score(y1, y2, *, labels=None, weights=None, sample_weight=None, replace_undefined_by=nan)| Name | Type | Description |
|---|---|---|
y1 | array-like | First labeling or annotator’s target values. |
y2 | array-like | Second labeling or annotator’s target values. |
labels | array-like, default=None | Optional explicit set of labels included in the comparison. |
weights | {None, "linear", "quadratic"}, default=None | Optional disagreement weighting: None, "linear", or "quadratic". |
sample_weight | array-like, default=None | Optional per-sample weights. |
replace_undefined_by | float, default=np.nan | Value returned when the metric is undefined. |
float — The kappa statistic, a number between -1 and 1.
from sklearn.metrics import cohen_kappa_score
labeling1 = [2, 0, 2, 2, 0, 1]
labeling2 = [0, 0, 2, 2, 0, 2]
score = cohen_kappa_score(labeling1, labeling2, weights="quadratic")
print(score)Computes weighted agreement between two labelings; quadratic weighting gives greater penalty to larger category disagreements.
Assess consistency between two human labelers assigning binary or multiclass categories.
Compare ordinal ratings where larger category gaps should count as more severe disagreements.
Aggregate agreement when observations have unequal importance or sampling frequency.
It is a chance-adjusted agreement statistic. If \(p_o\) is observed agreement and \(p_e\) is agreement expected from random assignments, it computes \(\kappa=(p_o-p_e)/(1-p_e)\).
Follow-up: What does a negative result indicate? It indicates agreement below the level expected by chance; zero corresponds to chance-level agreement.
weights controls how disagreements are scored. With no weights, disagreements are treated equally; ordinal data can use linear or quadratic weighting to reflect category distance.
Follow-up: When would quadratic weighting be preferable? Use it when disagreements farther apart should receive substantially larger penalties than adjacent disagreements.
y1 and y2 are the two labelings being compared, and each sample position must correspond across them. labels can define the label set, while sample_weight gives individual observations different influence.
Follow-up: What is the purpose of replace_undefined_by? It specifies the value returned when the metric is undefined because its calculation requires division by zero.
accuracy_scorebalanced_accuracy_scoreconfusion_matrixmatthews_corrcoef