What is the Shapiro-Wilk test for normality?
Sometimes we want to know whether our sample data looks as though it is drawn from the normal distribution. To determine that, we perform a normality test. There are many normality tests. This test is good for thousands of observations or smaller. The Shapiro-Wilk test for normality is named after Samuel Shapiro and Martin Wilk.
How to perform the Shapiro-Wilk test for normality using Python?
We can use the following Python code to test for normality.
from scipy.stats import shapiro
from numpy.random import randn
data = 5*randn(100) + 10
print(data)
test_statistic, p_value = shapiro(data)
print("Test Statistic: ", test_statistic)
print("p-value: ", p_value)
Here, we are using the randn() function from the numpy.random() module to generate 100 random numbers that have a standard deviation of 5 and a mean of 10. After that, we are using the shapiro() function from the scipy.stats module to test whether the data is normal.
Please note that the shapiro() function takes the data as input and returns test statistic and p-value as output. If …








































0 Comments