我已经针对大量理论概率分布对我的分布进行了单边 KS 测试(观察公共交通公共交通网络的占用情况,值从 0 到 100):
cdfs = [
"norm", #Normal (Gaussian)
"alpha", #Alpha
"anglit", #Anglit
"arcsine", #Arcsine
"beta", #Beta
"betaprime", #Beta Prime
"bradford", #Bradford
"burr", #Burr
"cauchy", #Cauchy
....
]
for cdf in cdfs:
#fit our data set against every probability distribution
parameters = eval("scipy.stats."+cdf+".fit(data_sample)");
#Applying the Kolmogorov-Smirnof one sided test
D, p = scipy.stats.kstest(data_sample, cdf, args=parameters);
#pretty-print the results
print (cdf.ljust(16) + ("p: "+str('{0:.10f}'.format(p)).ljust(40)+"D: "+str('{0:.10f}'.format(D))));
根据我对单面 KS-Test 的理解,最适合我的数据的理论分布是单面 KS-Test 返回大 p 值和低 D-KSstatistic 值的分布。
据此,最佳拟合是:
cdf: invweibull p:0.1624542096 D:0.0352622822
cdf: genextreme p:0.1624292228 D:0.0352633673
cdf: nct p:0.1280588168 D:0.0369024688
cdf: invgamma p:0.1273446642 D:0.0369401507
cdf: johnsonsu p:0.0449026953 D:0.0433976894
cdf: invgauss p:0.0336248605 D:0.0450259762
(...)
cdf: frechet_l p:0.0000000000 D:0.8405035144
cdf: reciprocal p:0.0000000000 D:0.9380000000
cdf: truncnorm p:0.0000000000 D:0.9380000000
cdf: powernorm p:0.0000000000 D:1.0000000000
此外,当我尝试将这些所谓的最佳拟合分布直观地拟合到我的数据时,有些东西并没有加起来:
from scipy.stats import invgauss, invweibull, genextreme
fig, ax = plt.subplots(1, 1)
mu = 10.145462645553
x = np.linspace(invgauss.ppf(0.75, mu), invgauss.ppf(0.975, mu), 100)
ax.plot(x, invgauss.pdf(x, mu), 'r-', color='green', lw=1, alpha=0.6, label='invgauss pdf')
c = 0.8
y = np.linspace(invweibull.ppf(0.75, c), invweibull.ppf(0.975, c), 100)
ax.plot(y, invweibull.pdf(y, c), 'r-', color='red', lw=1, alpha=0.6, label='invweibull pdf')
c = -1.5
z = np.linspace(genextreme.ppf(0.75, c), genextreme.ppf(0.96, c), 100)
ax.plot(z, genextreme.pdf(z, c), 'r-', lw=1, color='yellow', alpha=0.6, label='genextreme pdf')
ax.hist(data_sample, normed=True, histtype='stepfilled', bins=20, alpha=0.2, label='my distribution')
ax.legend(loc='best', frameon=False)
plt.show()
结果似乎与我的数据不匹配 invgauss、invweibull 或 genextreme 概率分布。
我做错了什么或假设 KS 测试结果有问题吗?
我的分布中的数据样本:
array([ 29.75, 0.8 , 9. , 4.77, 28.75, 31.1 , 52.12, 5. ,
10.55, 17.26, 19.28, 25.77, 53.13, 28. , 4.1 , 2.92,
40.4 , 15.33, 10.62, 20.6 , 26.11, 15. , 5.3 , 38.87,
1.28, 1.5 , 20.88, 16. , 10.33, 6.5 , 6. , 22.5 ,
7.88, 2.72, 60.33, 26.14, 18. , 18.58, 25. , 69.62,
0.5 , 0. , 26.87, 11.85, 13.16, 39.45, 17.6 , 14.66,
84.52, 3.62, 30.33, 4.25, 25. , 35. , 28.85, 48.37,
12.55, 50. , 22.94, 7.42, 2.37, 49.66, 22.94, 7.57,
101.12, 4.42, 43.88, 7. , 13. , 31.12, 20.71, 0. ,
22. , 21.34, 23.61, 0.5 , 16.23, 27.11, 2.22, 59. ,
24.41, 41.69, 2.68, 49. , 51.6 , 95.8 , 0. , 26.8 ,
66. , 43.02, 13.85, 46.91, 38.77, 6.5 , 24. , 54.14,
50.81, 21.55, 19.22, 12.83])
解决方案
请参阅接受的答案以获取更多详细信息。仅供参考,在估计正确的参数并将其传递给单边 KS 测试认为与我自己的分布相似的最相似的理论分布后,我能够直观地确认分布相似性。