gpt4 book ai didi

python - 类型错误 :ndarray not callable in scipy. stats.kstest()

转载 作者:太空宇宙 更新时间:2023-11-04 00:50:17 27 4
gpt4 key购买 nike

我正在尝试执行 Kolmogorov-Smirnov 检验来比较经验分布和 F 分布(我知道这些不能直接比较,但我会使用 Bootstrap )。我在使用 scipy KS 测试时遇到问题:

readLengths = [list,of,int,values,...]
x = stats.f.fit(readLengths)
dfn=x[0]
dfd=x[1]
stats.kstest(readLengths,stats.f.rvs(dfn,dfd,size=100))

我遇到了错误

TypeError: 'numpy.ndarray' object is not callable

它指向 stats.kstest 行。我认为这是 readLengths 数组的问题,但文档说它可以采用一维数组,所以不确定为什么我会遇到这个问题。此外,有趣的是,在此函数中,您可以使用“norm”命名正态分布,但“f”似乎无效,尽管它是 F 分布的 scipy 名称。

最佳答案

来自 the docs :

cdf : str or callable

If a string, it should be the name of a distribution in scipy.stats. If rvs is a string then cdf can be False or the same as rvs. If a callable, that callable is used to calculate the cdf.

kstest 的第二个参数应该是字符串 或接受分位数作为输入并返回 CDF 的可调用对象。相反,你正在传递它

stats.f.rvs(dfn,dfd,size=100)

计算结果为 np.ndarray


一个选项是使用您想要的参数构建一个卡住的 PDF,然后将其 .cdf 方法作为第二个参数传递给 kstest:

fdist = stats.f(dfn, dfd)
d, p = stats.kstest(readLengths, fdist.cdf)

关于python - 类型错误 :ndarray not callable in scipy. stats.kstest(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37424877/

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