TorchedUp
LearnBetaProblemsSystem DesignSoonPremium
TorchedUp
LearnBetaProblemsSystem DesignSoonPremium
←

123. Cohen's Kappa

Medium

Implement Cohen's kappa, an inter-rater agreement metric that corrects for chance agreement.

Signature: def cohen_kappa(rater1: list, rater2: list) -> float

Where:

  • p_o = observed agreement = fraction of items both raters agree on
  • p_e = expected agreement by chance, computed from the marginals (sum_k p1_k * p2_k)
  • kappa = (p_o - p_e) / (1 - p_e)

Returns 1.0 for perfect agreement, 0.0 for chance-level, negative for worse-than-chance.

Math

κ=1−pe​po​−pe​​

Asked at

NumPy

import numpy as np

 

def cohen_kappa(...):

    pass

🔒

Premium problem

Free accounts include problems #1–20. Upgrade to unlock the editor, hidden test cases, and reference solutions for every problem.

Upgrade to PremiumBack to problems

Already premium?