Skip to content
DeepForgeby svx
All problems
MediumStatisticsst-077

Kolmogorov-Smirnov Statistic (Two-Sample)

Problem

Return the two-sample Kolmogorov-Smirnov statistic: the maximum absolute difference between the two empirical CDFs, evaluated at the combined sorted values. Return 0.0 if either sample is empty.

Hint

At each distinct value compare the two cumulative proportions.

Test cases

case 1
in: [[1,2,3,4,5],[6,7,8,9,10]]
expected: 1
case 2
in: [[1,2,3],[1,2,3]]
expected: 0
case 3
in: [[1,2,3,4],[2,4,6,8]]
expected: 0.5
case 4
in: [[1],[2]]
expected: 1
case 5
in: [[],[1,2]]
expected: 0
Starter codePython
def ks_statistic(x, y):
    # Your code here
    pass

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