TensorTonicTensorTonic
Problems
Study PlansProjectsNewInterviewPricingFeedback
Problems
Loading...
1 / 1

Cohen's Kappa

Metrics & Evaluation
Easy

Compute Cohen’s kappa for two raters. It corrects observed agreement for agreement expected from each rater’s label frequencies.

κ=po−pe1−pe\kappa=\frac{p_o-p_e}{1-p_e}κ=1−pe​po​−pe​​ po=matching labelsnp_o=\frac{\text{matching labels}}{n}po​=nmatching labels​ pe=∑kc1,knc2,knp_e=\sum_k \frac{c_{1,k}}{n}\frac{c_{2,k}}{n}pe​=k∑​nc1,k​​nc2,k​​

Here, nnn is the number of rated items, kkk ranges over every label used by either rater, and c1,kc_{1,k}c1,k​ and c2,kc_{2,k}c2,k​ are the raters’ counts for label kkk. If pe=1p_e=1pe​=1, return 1.0. Otherwise return the kappa score as a Python float.

Loading visualization...

Examples

Input: rater1 = [0, 1, 0, 1], rater2 = [0, 1, 0, 1]

Output: 1

Explanation: Every paired rating agrees, so kappa indicates perfect agreement.

Input: rater1 = [0, 0, 1, 1], rater2 = [0, 1, 1, 0]

Output: 0

Hint 1

Build the label set with set(rater1) | set(rater2).

Hint 2

For each label, multiply its two separate frequency fractions and add them to p_e.

Requirements

  • Compute observed agreement from paired labels
  • Compute expected agreement from each rater’s separate label frequencies
  • Include labels appearing in either list
  • Return 1.0 when expected agreement equals one

Constraints

  • Both label lists have equal nonzero length
  • Labels are hashable values
Try Similar Problems
Classification MetricsMetrics F1 MicroConfusion Matrix NormLog Loss Per SampleExpected Calibration Error

Sign in to take notes on this problem

Case 1
Case 2

Accepts: array

Accepts: array

You must run your code first.
PrevNext

Cohen's Kappa

Metrics & Evaluation
Easy

Compute Cohen’s kappa for two raters. It corrects observed agreement for agreement expected from each rater’s label frequencies.

κ=po−pe1−pe\kappa=\frac{p_o-p_e}{1-p_e}κ=1−pe​po​−pe​​ po=matching labelsnp_o=\frac{\text{matching labels}}{n}po​=nmatching labels​ pe=∑kc1,knc2,knp_e=\sum_k \frac{c_{1,k}}{n}\frac{c_{2,k}}{n}pe​=k∑​nc1,k​​nc2,k​​

Here, nnn is the number of rated items, kkk ranges over every label used by either rater, and c1,kc_{1,k}c1,k​ and c2,kc_{2,k}c2,k​ are the raters’ counts for label kkk. If pe=1p_e=1pe​=1, return 1.0. Otherwise return the kappa score as a Python float.

Loading visualization...

Examples

Input: rater1 = [0, 1, 0, 1], rater2 = [0, 1, 0, 1]

Output: 1

Explanation: Every paired rating agrees, so kappa indicates perfect agreement.

Input: rater1 = [0, 0, 1, 1], rater2 = [0, 1, 1, 0]

Output: 0

Hint 1

Build the label set with set(rater1) | set(rater2).

Hint 2

For each label, multiply its two separate frequency fractions and add them to p_e.

Requirements

  • Compute observed agreement from paired labels
  • Compute expected agreement from each rater’s separate label frequencies
  • Include labels appearing in either list
  • Return 1.0 when expected agreement equals one

Constraints

  • Both label lists have equal nonzero length
  • Labels are hashable values
Try Similar Problems
Classification MetricsMetrics F1 MicroConfusion Matrix NormLog Loss Per SampleExpected Calibration Error

Sign in to take notes on this problem

Case 1
Case 2

Accepts: array

Accepts: array

You must run your code first.