Skip to content
DeepForgeby svx
All problems
MediumML Fundamentalsml-270

Sample Ratio Mismatch

Problem

Compute the sample ratio mismatch chi-square: expected_i = total * ratio_i, statistic = sum((observed - expected)^2 / expected).

Return 0.0 when the total is 0.

Hint

A large sample ratio mismatch invalidates the randomization of the experiment.

Test cases

case 1
in: [[45,55],[0.5,0.5]]
expected: 1
case 2
in: [[50,50],[0.5,0.5]]
expected: 0
case 3
in: [[30,70],[0.5,0.5]]
expected: 16
case 4
in: [[10],[1]]
expected: 0
Starter codePython
def sample_ratio_mismatch(observed, expected_ratios):
    # Your code here
    pass

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