gpt4 book ai didi

python - scipy stats kstest 针对 x=y?

转载 作者:太空宇宙 更新时间:2023-11-03 14:47:13 25 4
gpt4 key购买 nike

这个问题我已经困惑了一段时间,希望得到一些帮助。

我正在尝试使用scipy.stats.kstest来针对另一个简单的x=y分布来测试我的分布,以便我可以获得p值。在在线示例中,它给出了类似的内容:

>>> x = np.linspace(-15, 15, 9)
>>> scipy.stats.kstest(x, 'norm')
(0.44435602715924361, 0.038850142705171065)

但我不确定如何将预期分布从 norm 修改为 x=y?另外,我的“真实”分布有 x 和 y 值(它是均匀分布的 cdf)。我该如何将其插入此?

最佳答案

您似乎正在寻找scipy.stats.ks_2samp:

This is a two-sided test for the null hypothesis that 2 independent samples are drawn from the same continuous distribution.

import numpy as np
from scipy import stats
np.random.seed(123)

# Draw random samples from two normal distributions
# with different means/stdevs. The resulting pvalue
# be low (high significance/reject the null).
rvs1 = stats.norm.rvs(size=400, loc=0., scale=1)
rvs2 = stats.norm.rvs(size=400, loc=0.5, scale=1.5)
p_lo = stats.ks_2samp(rvs1, rvs2)[1]
print(p_lo)
# 1.29793098188e-10

# Same test for two random samples drawn from same distribution
# should yield high p value.
rvs3 = stats.norm.rvs(size=400, loc=0.01, scale=1)
p_hi = stats.ks_2samp(rvs1, rvs3)[1]
print(p_hi)
# 0.855599637503

关于python - scipy stats kstest 针对 x=y?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46145459/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com