scipy check normal distribution

34

from scipy import stats
pts = 1000
np.random.seed(28041990)
a = np.random.normal(0, 1, size=pts)
b = np.random.normal(2, 1, size=pts)
x = np.concatenate((a, b))

k2, p_value = stats.normaltest(x)

alpha = 1e-3
print("p_value = {:g}".format(p))
# p_value = 3.27207e-11

if p_value < alpha:  # null hypothesis: x comes from a normal distribution
  print("The null hypothesis can be rejected")
else:
  print("The null hypothesis cannot be rejected")
# The null hypothesis can be rejected

Comments

Submit
0 Comments