Python scipy.stats.kstest,具有非范数分布
我在scipy(scipy.stats.kstest)中使用Kolmogorov-Smirnov测试时遇到问题。在线文档(http://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.kstest.html)表示它需要示例、cdf与仅命名一个scipy.stats发行版的选项、cdf参数(和几个可选值)进行比较 只要所选择的cdf不需要任何额外的参数,一切都很正常Python scipy.stats.kstest,具有非范数分布,python,scipy,Python,Scipy,我在scipy(scipy.stats.kstest)中使用Kolmogorov-Smirnov测试时遇到问题。在线文档(http://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.kstest.html)表示它需要示例、cdf与仅命名一个scipy.stats发行版的选项、cdf参数(和几个可选值)进行比较 只要所选择的cdf不需要任何额外的参数,一切都很正常 teststat,pval=stats.kstest(sample
teststat,pval=stats.kstest(sample,'norm')
(其中sample是一个值列表。)
然而,对于其他需要额外耕地的分布,如t、chisquared等,它对我不起作用。如果没有进一步的论据,这是正确的
teststat,pval=stats.kstest(sample,'t')
TypeError: _cdf() takes exactly 3 arguments (2 given)
如果给出一个论点
teststat,pval=stats.kstest(sample,'t',24)
它抱怨
TypeError: cdf() argument after * must be a sequence, not int
现在我不确定这意味着什么,但它似乎不需要int,24,而是一个int,24的序列。然而:
teststat,pval=stats.kstest(sample,'t',24)
TypeError: cdf() argument after * must be a sequence, not int
手动定义分发也不会产生更好的结果,因为它觉得这是不可调用的:
numargs = stats.t.numargs
[ df ] = [0.9,] * numargs
rv = stats.t(df)
teststat,pval=stats.kstest(sample,stats.t.cdf(numpy.linspace(0, numpy.minimum(rv.dist.b, 3)),df))
TypeError: 'numpy.ndarray' object is not callable
我该怎么做才能让它工作?(谷歌搜索kstest函数或各种错误消息都不会找到任何有用的答案。)
感谢查看此错误:
TypeError: cdf() argument after * must be a sequence, not int
让我觉得你是对的,它需要一个序列,而不是一个整数。医生说
args : tuple, sequence
distribution parameters, used if rvs or cdf are strings
这似乎有效:
>>> import scipy.stats
>>> sample = scipy.stats.t(1).rvs(size=10**6)
>>> scipy.stats.kstest(sample, 't', (1,))
(0.0006249662221899932, 0.82960203415652445)
或者更明确地说:
>>> scipy.stats.kstest(sample, 't', args=(1,))
(0.0006249662221899932, 0.82960203415652445)
谢谢DSM,你当然是对的。(x,)是表示序列的正确方式;我不熟悉那种变量类型。谢谢