简体   繁体   English

Python stats.kstest错误?

[英]Python stats.kstest bug?

I find the way to interpret the shape of random sample has big impact on kstest. 我发现解释随机样本形状的方法对kstest有很大影响。 I try the following codes: 我尝试以下代码:

import numpy as np
from scipy import stats

N = 260
np.random.seed(1)
X = np.random.rand(N)
Xarray = X.reshape(N,1)
XarrayT = Xarray.T

print('X' + str(X.shape) + ': ' + str(stats.kstest(X, 'uniform') ) )
print( 'Xarray' + str(Xarray.shape) + ':' + str( stats.kstest(Xarray, 'uniform') ) )
print( 'XarrayT' + str(XarrayT.shape) + ': ' + str( stats.kstest(XarrayT, 'uniform') ) )

It gives the results: 结果如下:

X(260,): KstestResult(statistic=0.052396054203786291, pvalue=0.46346349447418866)
Xarray(260, 1):KstestResult(statistic=0.99988562518265511, pvalue=0.0)
XarrayT(1, 260): KstestResult(statistic=0.99988562518265511, pvalue=0.00022874963468977327)

where X, Xarray, XarrayT have the same data, except that they have different shape. 其中X,Xarray,XarrayT具有相同的数据,但形状不同。 And the pvalues are totally different. p值完全不同。 Is it due to a bug or I miss some point in order to use kstest correctly? 是由于错误还是为了正确使用kstest而错过了一点?

Thanks! 谢谢!

Well, the scipy kstest documentation tells us it should be a 1d array. 好吧, 科学的kstest文档告诉我们它应该是一数组。

if we run the following: 如果我们运行以下命令:

print('X ' + 'ndimensions=' + str(X.ndim) + ' ' + (str(stats.kstest(X, 'uniform'))))

We see 1 dimensions in the target array. 我们在目标数组中看到1个维度。

output: 输出:

X ndimensions=1 KstestResult(statistic=0.052396054203786291, pvalue=0.46346349447418866)

However, when we try our other Xarray: 但是,当我们尝试其他Xarray时:

print('Xarray ' + 'ndimensions=' + str(Xarray.ndim) + ' ' + (str(stats.kstest(Xarray, 'uniform'))))

Xarray ndimensions=2 KstestResult(statistic=0.99988562518265511, pvalue=0.0)

This would indicate to me the use of two dimensions in the input array is screwing up the Kolmogorov-Smirnov test for goodness of fit. 这向我表明,在输入数组中使用二维会破坏Kolmogorov-Smirnov检验的拟合优度。

I would also suggest reading the answers at this stackoverflow question 我也建议阅读这个stackoverflow问题的答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Scipy的stats.kstest模块进行拟合优度测试 - Using Scipy's stats.kstest module for goodness-of-fit testing TypeError:ndarray在scipy.stats.kstest()中不可调用 - TypeError:ndarray not callable in scipy.stats.kstest() scipy.stats.kstest与除了norm之外的发行版 - scipy.stats.kstest with distributions other than norm 使用 scipy.stats.kstest 对大型集进行均匀性测试 - Uniformity test on a large set using scipy.stats.kstest 如何使用scipy.stats.kstest /关于Kolmogorov-Smirnov测试的基本问题 - how to use scipy.stats.kstest/basic questions about Kolmogorov–Smirnov test 如何解释`scipy.stats.kstest`和`ks_2samp`来评估数据的“拟合”? - How to interpret `scipy.stats.kstest` and `ks_2samp` to evaluate `fit` of data to a distribution? scipy.stats kstest 用于泊松分布/与 (x2) 边一起工作但不与 (x1) 边一起工作? - scipy.stats kstest for Poisson distribution / works with (x2) sided but not with (x1) sided? 当我对大型数据集使用 scipy.stats.kstest() 时 p_value 为 0 - p_value is 0 when I use scipy.stats.kstest() for large dataset 如何使用scipy.stats.kstest将样本与自定义概率分布进行比较? - How to compare a sample to a self-defined probability distribution using scipy.stats.kstest? 使用 scipy.stats.kstest 查看随机生成的数字是否遵循指定分布 - Use the scipy.stats.kstest to see if the randomly generated numbers follow a specified distribution
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM