简体   繁体   中英

Check Normal distribution with Kolmogorov test

I am a learning statistics using python, and I have a task to check that data have Normal Distribution with mean=10 and dispersion=5.5. I've checked scipy.stats.kstest function, but I don't understand how to interpret the results, and where I should pass mean and dispersion args.

Thank you, for your help

Generate a dataset

import scipy
import matplotlib.pyplot  as plt
# generate data with norm(mean = 0,std = 15)
data = scipy.stats.norm.rvs(loc = 0,scale = 15,size = 1000,random_state = 0)

Perfrom KS-test

# perform KS test on your sample versus norm(10,5.5)
D, p = scipy.stats.kstest(data, 'norm', args= (10, 5.5))
test = 'Reject' if p < 0.05 else 'Not reject'
print(f'D-statistics: {D:.4f},\np-value: {p:.4f}, \ntest-result: {test}')

Out:

'D-statistics:0.5091,p-value:0.0000,test-result:Reject'

Add a plot with distributions and your data

# draw a plot to see the distribution and your data hist
# draw a plot to see the distribution and your data hist
fig, ax = plt.subplots(1, 1)
x = np.linspace(data.min(),data.max(),100)
ax.plot(x, scipy.stats.norm.pdf(x,loc = 10, scale = 5.5), 'r-', color='green', lw=1, alpha=0.6, label='norm(10,5.5) pdf')
ax.hist(data, normed=True, histtype='stepfilled', bins=20, alpha=0.2, label='my data distribution')
ax.legend(loc='best', frameon=False)
plt.title('norm(10,5.5) vs. data')
plt.show()

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM