scipy check normal distribution

Solutions on MaxInterview for scipy check normal distribution by the best coders in the world

showing results for - "scipy check normal distribution"
Francesco
26 Jul 2018
1from scipy import stats
2pts = 1000
3np.random.seed(28041990)
4a = np.random.normal(0, 1, size=pts)
5b = np.random.normal(2, 1, size=pts)
6x = np.concatenate((a, b))
7
8k2, p_value = stats.normaltest(x)
9
10alpha = 1e-3
11print("p_value = {:g}".format(p))
12# p_value = 3.27207e-11
13
14if p_value < alpha:  # null hypothesis: x comes from a normal distribution
15  print("The null hypothesis can be rejected")
16else:
17  print("The null hypothesis cannot be rejected")
18# The null hypothesis can be rejected