Skip to content

Kolmogorov Smirnov test

Maurice HT Ling edited this page Aug 14, 2021 · 1 revision

Purpose: To test whether 2 distributions are equal.

Null hypothesis: Observed distribution = Expected distribution

Alternate hypothesis: Observed distribution ≠ Expected distribution

Code:

>>> from scipy import stats
>>> observed = [16, 18, 16, 14, 12, 12]
>>> expected = [16, 16, 16, 16, 16, 8]
>>> result = stats.ks_2samp(observed, expected)
>>> print("KS = %.2f" % result.statistic)
KS = 0.33
>>> print("p-value = %.2f" % result.pvalue)
p-value = 0.93

Reference:

  1. Kolmogorov AN. 1933. Sulla Determinazione Empirica di Una Legge di Distribuzione. Giornale dell'Istituto Italiano degli Attuari 4, 83-91.
  2. Smirnov N. 1948. Table for estimating the goodness of fit of empirical distributions. Annals of Mathematical Statistics 19(2), 279–281.
Clone this wiki locally