Skip to content
DeepForgeby svx
All problems
MediumStatisticsst-251

Cohen's Kappa Agreement

Problem

Return Cohen's kappa (po - pe) / (1 - pe) for two raters, where po is observed agreement and pe is the sum over labels of the product of each rater's label marginals. Return 0.0 when the inputs are empty, have different lengths, or pe equals 1.0.

Test cases

case 1
in: [["a","b","a","b"],["a","b","b","b"]]
expected: 0.5
case 2
in: [["a","a"],["a","a"]]
expected: 0
case 3
in: [["a","b"],["b","a"]]
expected: -1
case 4
in: [[],[]]
expected: 0
Starter codePython
def cohens_kappa(a, b):
    # Your code here
    pass

4 test cases · run your code against them in the editor