Python normality test: test whether the data obey the normal distribution

The Shapiro Wilk test can be used, and the ready-made wheels in SciPy can be used directly. The code is as follows:

>>> from scipy import stats
>>> import numpy as np
>>> np.random.seed(12345678)
>>> x = stats.norm.rvs(loc=5, scale=3, size=100)
>>> shapiro_test = stats.shapiro(x)
>>> shapiro_test
ShapiroResult(statistic=0.9772805571556091, pvalue=0.08144091814756393)
>>> shapiro_test.statistic
0.9772805571556091
>>> shapiro_test.pvalue
0.08144091814756393

The zero hypothesis of Shapiro Wilke test is that the data obey normal distribution, and the zero hypothesis can be overturned when the pvalue is small. Although the pvalue in the above code is small, it is still larger than 0.05, so it can be considered that the data is subject to normal distribution.

see also

scipy.stats.shapiro

Read More: