如何通过卡方准则检验样本是否符合给定的分布?
编程语言-Python
我使用Numpy库生成了一个这样的样本,大约大小是100万。
uniformSample = UniformSample(1000000)
uniformSample.generate()
def generate(self, a=0.0, b=1.0):
self.left = a
self.right = b
self.sample = [np.random.uniform(low=self.left, high=self.right) for _ in range(self.size)]
我有各种样本特征,例如均值、方差、标准差等。 我需要检查给定的样本是否对应于一种或另一种分布类型(在我的例子中有 8 种类型)。您需要使用卡方检验来检查这一点。亲爱的数学家和程序员,你们能帮我以最优雅、最简单的方式检查样本对任何分布的符合性吗?
欢迎使用Python中的内置函数和库!
欢迎使用代码示例来回答我的问题!
Programming language - Python
I generate a sample like this, using the Numpy library, the approximate size is 1 million.
uniformSample = UniformSample(1000000)
uniformSample.generate()
def generate(self, a=0.0, b=1.0):
self.left = a
self.right = b
self.sample = [np.random.uniform(low=self.left, high=self.right) for _ in range(self.size)]
I have various sample characteristics such as mean, variance, standard deviation and others.
I need to check that the given sample corresponds to one or another type of distribution (there are 8 types in my case). You need to check this using the chi-square test. Dear mathematicians and programmers, can you please help me to check the conformity of the sample to any distribution in the most elegant and simple way possible?
Using built-in functions and libraries in Python is welcome!
Code examples in response to my question is welcome!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用Kolmogorov-Smirnov测试测试给定的数据集是否来自给定的分布。有一个 scipy 函数 scipy.stats.kstest 可以执行此操作。
您没有说明要测试的分布,但例如,您可以执行类似
“测试高斯分布”之类的操作。返回的
pvalue
是数据可能来自传递的分布的概率(在这种情况下,p 值应该非常小)。You can use the Kolmogorov-Smirnov test to test if a given data set could come from a given distribtuion. There is a
scipy
functionscipy.stats.kstest
that does this.You don't say what distribution you are testing against, but for example, you could do something like
To test against a Gaussian distribution. The
pvalue
returned is the probability that the data could come from the passed distribution (in this case the p-value should be extremely small).