concept
Judge agreement and uncertainty
Observed agreement and chance-adjusted Cohen kappa for paired categorical labels.
Formal Syntax & Structure
artificial-intelligence syntaxartificial-intelligence
agreement(a, b)Working Example
Example Snippetartificial-intelligence
from collections import Counterfrom fractions import Fraction
def agreement(a, b): if len(a) != len(b) or not a: raise ValueError("nonempty paired ratings required") n = len(a) observed = Fraction(sum(x == y for x,y in zip(a,b)), n) ca, cb = Counter(a), Counter(b) expected = Fraction(sum(ca[k]*cb[k] for k in ca), n*n) kappa = None if expected == 1 else (observed-expected)/(1-expected) return observed, kappa
p,k = agreement(["pass","pass","fail","fail"], ["pass","fail","fail","fail"])print(float(p), float(k))print(agreement(["pass"], ["pass"])[1])