Skip to content
DeepForgeby svx
All problems
MediumML Fundamentalsml-264

Chi-Square Drift Test

Problem

Compute the chi-square drift statistic between expected and actual counts: sum over bins with expected > 0 of (actual - expected)^2 / expected.

Empty input returns 0.0.

Hint

Large statistics indicate the actual distribution has drifted from expected.

Test cases

case 1
in: [[50,30,20],[40,40,20]]
expected: 5.333333333333334
case 2
in: [[50,30,20],[50,30,20]]
expected: 0
case 3
in: [[0,10],[5,5]]
expected: 2.5
case 4
in: [[],[]]
expected: 0
Starter codePython
def chi_square_drift(expected_counts, actual_counts):
    # Your code here
    pass

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