Python 中的 15 个统计假设检验2024 年 8 月 29 日 | 阅读 15 分钟 有数百种用于检验假设的统计检验。然而,机器学习项目只需要其中少数几种。在本教程中,我们将介绍一些最重要的假设检验,如果您想从事统计建模相关领域的工作,就必须了解它们。我们将使用 Python 编程语言来实现这些检验。 下面提到的每个假设检验都包含与该检验相关的以下信息
请注意,这些假设非常重要。如果违反了数据样本的预期分布或所需样本大小等假设,检验结果将不准确。基于这些结果的解释将高度不可靠。因此,在应用这些检验之前,检查这些假设非常重要。 数据样本通常需要足够大,才能揭示其分布情况,以便进行分析和说明领域。 在某些情况下,可以调整数据使其符合假设。仅举两个例子,这可以通过从接近正态分布的数据中去除异常值使其更接近正态分布,或者当给定数据样本的方差不同时调整检验的自由度来完成。 最后,对于某个特定问题(例如正态性),可能会有多种检验可用。通过统计学,我们无法获得问题的精确解决方案;相反,我们获得的是概率性解决方案。因此,通过以多种方式思考同一主题,我们可能会得出不同的答案。因此,可能需要多种检验来解决我们可能遇到的某些数据相关问题。 正态性检验在本节中,我们将看到用于检验给定数据样本是否具有高斯分布的检验。数据遵循高斯分布的假设是许多统计建模技术的基本要求。因此,这些检验非常重要。 Shapiro-Wilk 检验因此,此检验用于检验给定数据样本是否具有高斯分布或正态分布。 假设
解释 H0:样本遵循高斯分布 H1:给定样本不遵循高斯分布。 代码 输出 The statistic value is: 0.9621855020523071, and the p-value is 0.8104783892631531 The data does not follow a Gaussian distribution. D'Agostino's K^2 检验此检验用于检验给定数据样本是否为高斯分布。 假设
解释 H0:样本遵循高斯分布 H1:给定样本不遵循高斯分布。 代码 输出 The statistic value is: 1.0653637027947445, and the p-value is 0.5870285334466323 The data does not follow a Gaussian distribution Anderson-Darling 检验此检验用于检验给定数据样本是否为高斯分布。 假设
解释 H0:样本遵循高斯分布 H1:给定样本不遵循高斯分布。 代码 输出 The statistic value is: 0.20692157645671116 The critical value at 15.0% is 0.501 The data does not follow a Gaussian distribution at 15.0% The critical value at 10.0% is 0.57 The data does not follow a Gaussian distribution at 10.0% The critical value at 5.0% is 0.684 The data does not follow a Gaussian distribution at 5.0% The critical value at 2.5% is 0.798 The data does not follow a Gaussian distribution at 2.5% The critical value at 1.0% is 0.95 The data does not follow a Gaussian distribution at 1.0% 相关性检验现在我们将看到比较两个样本并判断它们是否相关的检验。 Pearson 相关系数此检验用于检验给定两个数据样本之间是否存在线性关系。 假设
解释 H0:给定两个样本不相关,即它们是独立的。 H1:给定样本之间存在某种依赖关系。 代码 输出 The statistic value is: 0.6135196215696078, and the p-value is 0.05922727627191346 The data samples are independent of each other Spearman 秩相关这是 Pearson 检验的进一步发展。它检验给定样本是否具有单调关系。这种关系可以是线性的也可以是非线性的。 假设
解释 H0:给定两个样本不相关,即它们是独立的。 H1:给定样本之间存在某种依赖关系。 代码 输出 The statistic value is: 0.6969696969696969, and the p-value is 0.02509667588225183 Both data samples are dependent on each other Kendall 秩相关这是 Pearson 检验的进一步发展。它检验给定样本是否具有单调关系。 假设
解释 H0:给定两个样本不相关。 H1:给定样本之间存在某种依赖关系。 代码 输出 The statistic value is: 0.5111111111111111, and the p-value is 0.04662257495590829 Both data samples are dependent on each other 卡方检验Pearson 检验只能用于数值。Spearman 和 Kendall 秩相关检验可用于序数数据。序数数据是具有一定顺序的分类数据。但对于名义数据(无序的分类数据),这些检验不能使用。要检验名义数据之间的依赖性或关系,我们使用卡方检验。 假设
解释 H0:给定两个样本不相关。 H1:给定样本之间存在某种依赖关系。 代码 输出 Expected Frequencies are [[27.03703704 26.54545455 31.95286195 29.49494949 30.96969697] [27.96296296 27.45454545 33.04713805 30.50505051 32.03030303]] The statistic value is: 1.8882030380034551, and the p-value is 0.7563117707680647 The data samples are independent of each other 平稳性检验时间序列是一个非常重要的话题。在时间序列上执行的模型要求时间序列数据是平稳的。因此,要应用任何模型,我们首先需要检查时间序列数据是否平稳。现在我们将看到用于检查数据平稳性的检验。 增广迪基-富勒单位根检验通过此检验,我们检查给定时间序列数据是否具有单位模根。或者,更专业地说,数据是否是自回归的?自回归时间序列是平稳的。如果时间序列具有单位模根,则它不平稳。 假设
解释 H0:时间序列具有单位根(序列不平稳)。 H1:不存在单位模根(序列是平稳的)。 代码 输出 The order of the autoregressive model is 1 The statistic value is: -10.232070586545865, and the p-value is 4.998574442108246e-18 The given time series is stationary Kwiatkowski-Phillips-Schmidt-Shin此检验用于检验给定时间序列是否具有平稳趋势。如果序列是趋势平稳的,则意味着该序列是确定性的。 假设
解释 H0:给定时间序列具有平稳趋势。 H1:给定时间序列不具有平稳趋势。 代码 输出 The order of the autoregressive model is 0 The statistic value is: 0.09930151338766009, and the p-value is 0.1 The given time series is not stationary 参数统计假设检验现在我们将看到参数检验。在这些检验中,我们检验一个或多个样本的某个参数是否等于或不同于某个值或彼此。 Student's t 检验在此检验中,参数是给定样本的均值。我们检查两个样本的均值是否独立,换句话说,是否彼此显着不同。 假设
解释 H0:给定样本的均值相等。 H1:给定样本的均值不相等。 代码 输出 The statistic value is: 0.6713796580759667, and the p-value is 0.5105037120903526 The given samples have equal mean values 配对 Student's t 检验在此检验中,参数也是均值。但是,此检验用于两个样本配对的情况。如果两个值是在相同样本经过某个处理前后观测到的,则称这两个样本是配对的。 假设
解释 H0:配对样本的均值相等。 H1:配对样本的均值不相等。 代码 输出 The statistic value is: 0.9502747511161275, and the p-value is 0.36679175997294733 The paired samples have equal mean values 方差分析检验 (ANOVA)在此检验中,我们使用方差来确定两个或多个样本是否彼此不同或相同。 假设
解释 H0:给定样本的均值相等。 H1:给定多个样本中的一个或多个均值不相等。 代码 输出 The statistic value is: 0.3557581063875854, and the p-value is 0.7038772383760818 The samples have equal mean values 非参数统计假设检验Mann-Whitney U 检验此检验将检验从两个独立总体数据中抽取的样本是否相等。 假设
解释 H0:独立样本的基础分布是相同的。 H1:独立样本的基础分布不同。 代码 输出 The statistic value is: 60.0, and the p-value is 0.47267559351158717 The samples have the same distributions Wilcoxon 符号秩检验此检验用于检验给定两个或多个配对观测样本的分布是否相等。 假设
解释 H0:独立样本的基础分布是相同的。 H1:独立样本的基础分布不同。 代码 输出 The statistic value is: 15.0, and the p-value is 0.232421875 The samples have the same distributions Kruskal-Wallis H 检验此检验用于检验给定两个或多个观测样本的分布是否相等。 假设
解释 H0:独立样本的基础分布是相同的。 H1:独立样本的基础分布不同。 代码 输出 The statistic value is: 0.5714285714285694, and the p-value is 0.4496917979688917 The samples have the same distributions Friedman 检验此检验用于检验给定两个或多个配对观测样本的分布是否相等。 假设
解释 H0:独立样本的基础分布是相同的。 H1:独立样本的基础分布不同。 代码 输出 The statistic value is: 2.4000000000000057, and the p-value is 0.3011942119122012 The samples have the same distributions 总结在本教程中,您了解了可以在机器学习项目中应用的主要假设检验。 特别是,您发现了
|
我们请求您订阅我们的新闻通讯以获取最新更新。