python - scipy kstest 在不同范围内不一致

标签 python scipy statistics kolmogorov-smirnov

好的,所以我尝试使用 kstest 的 scipys 实现作为评估哪种分布最适合数据的方法。我对 kstest 工作原理的理解是,统计量代表原假设的概率(即返回的概率是相关模型对于数据错误的概率)。对于 0.0 和 1.0 之间的均匀分布,这与预期的效果大致相同

a = np.random.uniform(size=4999)

print(scipy.stats.kstest(a, 'uniform', args=(0.0,1.0)))

KstestResult(statistic=0.010517039009963702, pvalue=0.63796173656227928)

但是,当我将均匀分布范围从 (0.0, 1.0) 移动到 (2.0,3.0) 时,K-S 统计量出奇地高

a = np.random.uniform(2.0, 3.0,size=4999)

print(scipy.stats.kstest(a, 'uniform', args=(2.0,3.0)))

KstestResult(statistic=0.66671700832788283, pvalue=0.0)

由于传递的参数与以前一样接近分布,因此第二种情况下的检验统计量的值是否也应该很低?

最佳答案

uniformnumpy(由您使用)和 scipy.stats(由 ks test 使用)版本的工作方式不同:

>>> np.random.uniform(2,3,5000).max()
2.9999333044165271
>>> stats.uniform(2,3).rvs(5000).max()
4.9995316751114043

numpy中,第二个参数被解释为上限,在scipy.stats中,它是scale参数,即宽度。

关于python - scipy kstest 在不同范围内不一致,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42183717/

相关文章:

python - 估算器管道的参数丢失无效

python 2.7 : knowing if it's a list of list of list OR a list of list

python - 为什么来自 scipy.stats.bartlett 的 Bartlett 测试将 nan 作为输出?

python - 使用 Scipy 的 stats.kstest 模块进行拟合优度测试

java - 计算标准偏差的在线算法

python - 检索 Kibana 中的额外字段

Pythonrequirements.txt 显示安装了哪个包?

python - 从 numpy 和 scipy.sparse 准备 tensorflow 的数据输入

python - 使用 scipy.io.savemat() 时如何不覆盖 .mat 文件?

python - scipy.stats.nanemean 文档?