【问题标题】:Python Trouble with Kolmogorov-Smirnov test non 'norm' distributionKolmogorov-Smirnov 测试非“正态”分布的 Python 问题
【发布时间】:2015-10-12 13:09:50
【问题描述】:

我确信答案很简单,但我不知道我做错了什么。

我想测试我拥有的一些样本数据是否可以来自广义极值或 pearson 3 型分布。

由于某种原因,我无法让kstest(t1, 'genextreme') 合作。但是,当我将其更改为 norm 时,它可以工作。

查看下面的部分代码和错误:

from scipy.stats import kstest
from scipy.stats import ks_2samp
import numpy as np
import csv


In [7]: from scipy.stats import genextreme

In [8]: t1 = TP['flow']
...: test_GEV = kstest(t1, 'genextreme')
...: 
Traceback (most recent call last):

File "<ipython-input-8-ebc8faf10381>", line 2, in <module>
  test_GEV = kstest(t1, 'genextreme')

File "/Applications/anaconda/lib/python2.7/site-    packages/scipy/stats/stats.py", line 3585, in kstest
    cdfvals = cdf(vals, *args)

  File "/Applications/anaconda/lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.py", line 1642, in cdf
args, loc, scale = self._parse_args(*args, **kwds)

TypeError: _parse_args() takes at least 2 arguments (1 given)


In [9]: t1 = TP['flow']
...: test_GEV = kstest(t1, 'norm')
...: 
In [10]: test_GEV
Out[10]: (0.99999925980208981, 0.0

看来它适用于norm,但不适用于genextreme ...我如何让kstest() 为除norm 之外的其他发行版工作?

谢谢

【问题讨论】:

    标签: python statistics scipy


    【解决方案1】:

    你必须通过函数来生成随机变量-(kstest DocString)

    所以对于你的例子:

    test_GEV = kstest(t1, scipy.stats.genextreme.rvs)
    

    对于 scipy_stats 中的任何分布,请调用 dist_name:

    test_ks = kstest(your_array,scipy.stats.dist_name.rvs)
    

    【讨论】:

      【解决方案2】:

      genextreme 有一个形状参数c,因此您必须使用kstestargs 参数来完全定义分布。 genextreme 还具有所有 scipy 单变量分布所具有的标准 locscale 参数。如果您不使用args 来指定这些,则分别使用默认值0 和1。您可以选择要测试 t1genextreme 分布的参数 clocscale

      要完全明确您正在使用的发行版,您应该使用以下内容:

      c = 1.0
      loc = 0.0
      scale = 1.0
      test_GEV = kstest(t1, 'genextreme', args=(c, loc, scale))
      

      【讨论】:

        猜你喜欢
        • 2016-10-04
        • 2011-12-15
        • 2017-11-07
        • 2021-06-12
        • 2012-06-08
        • 1970-01-01
        • 1970-01-01
        • 2018-03-10
        • 1970-01-01
        相关资源
        最近更新 更多