← retour aux snippets

scipy.stats: t-test, chi2, KS

Tests d'hypothèses classiques sur distributions.

objectif

Tests d’hypothèses classiques sur distributions.

code minimal

from scipy import stats
import numpy as np
rng = np.random.default_rng(0)
a = rng.normal(size=50); b = rng.normal(size=50)
t, p = stats.ttest_ind(a, b, equal_var=False)
print(p >= 0.0)

utilisation

from scipy import stats
import numpy as np
obs = np.array([[10, 20],[20, 10]])
chi2, p, dof, exp = stats.chi2_contingency(obs)
print(int(dof))

variante(s) utile(s)

from scipy import stats
x = [0.1, 0.2, 0.3]; y = [0.15, 0.25, 0.35]
stat, p = stats.ks_2samp(x, y)
print(p <= 1.0)

notes

  • Contrôler les hypothèses (variance, indépendance, effectifs).