def test_two_variables(self): """ 检查正态分布的假设检验结果 """ array_1 = DistributionSampling(seed=2).generate_normal_samplings( mu=3, sigma=3, size=1000 ) array_2 = DistributionSampling(seed=3).generate_normal_samplings( mu=3, sigma=4, size=1000 ) array_3 = DistributionSampling(seed=4).generate_normal_samplings( mu=4, sigma=3, size=1000 ) array_4 = DistributionSampling(seed=5).generate_normal_samplings( mu=4, sigma=3, size=1000 ) array_5 = DistributionSampling(seed=6).generate_normal_samplings( mu=5, sigma=3, size=1000 ) # 检查双侧结果,方差一致 self._check_alternative(array_3, array_4, TTestAlternative.TWO_SIDED) # 检查双侧结果,方差不一致 self._check_alternative(array_1, array_2, TTestAlternative.TWO_SIDED) # 检查LESS self._check_alternative(array_3, array_1, TTestAlternative.LESS) # 检查more self._check_alternative(array_4, array_5, TTestAlternative.GREATER)
def test_chi_square(self): array_1 = DistributionSampling(seed=1).generate_bernoulli_samplings( 0.5, 1000) array_2 = DistributionSampling(seed=2).generate_bernoulli_samplings( 0.6, 1000) array_3 = DistributionSampling(seed=3).generate_bernoulli_samplings( 0.5, 1000) test_result = ChiSquareIndependentTwoVariables(array_1, array_2).test() self.assertTrue(test_result.rejected) test_result = ChiSquareIndependentTwoVariables(array_1, array_3).test() self.assertTrue(not test_result.rejected)
def test_normal_result(self): """ 检查正态分布的假设检验结果 """ array = DistributionSampling.generate_normal_samplings(mu=5, sigma=3, size=2000) # 检查双侧结果 student_t_test_one_sample = StudentTTestOneVariable( array, 6, 0.05, TTestAlternative.TWO_SIDED) two_side_result = student_t_test_one_sample.test() self.assertTrue(two_side_result.condition_satisfied) self.assertTrue(two_side_result.rejected) # 检查小于的结果 student_t_test_one_sample = StudentTTestOneVariable( array, 4, 0.05, TTestAlternative.LESS) less_result = student_t_test_one_sample.test() self.assertTrue(less_result.condition_satisfied) self.assertTrue(not less_result.rejected) # 检查大于的结果 student_t_test_one_sample = StudentTTestOneVariable( array, 6, 0.05, TTestAlternative.GREATER) greater_result = student_t_test_one_sample.test() self.assertTrue(greater_result.condition_satisfied) self.assertTrue(not greater_result.rejected)
def test_one_way(self): array_1 = DistributionSampling(seed=1).generate_bernoulli_samplings( 0.5, 1000) array_2 = DistributionSampling(seed=22).generate_bernoulli_samplings( 0.6, 20000) array_3 = DistributionSampling(seed=3).generate_normal_samplings( 0.6, 0.2, 2000) array_4 = DistributionSampling(seed=4).generate_normal_samplings( 0.7, 0.1, 1000) array_5 = DistributionSampling(seed=22).generate_bernoulli_samplings( 0.6, 20000) result = OneWayAnalysis(array_1, array_2).test() self.assertTrue(result.rejected) result = OneWayAnalysis(array_3, array_4).test() self.assertTrue(result.rejected) result = OneWayAnalysis(array_2, array_5).test() self.assertTrue(not result.rejected)
def test_not_normal(self): """ 检验对于数据是否满足正态分布的判断是否有效 """ array = DistributionSampling.generate_exponential_samplings(size=1000) student_t_test_one_sample = StudentTTestOneVariable( array, 0, 0.05, TTestAlternative.TWO_SIDED) result = student_t_test_one_sample.test() self.assertTrue(not result.condition_satisfied)
def test_two_variables(self): """ 检查正态分布的假设检验结果,这里暂时直接将随机数排序当做配对样本。 """ array_1 = DistributionSampling.generate_normal_samplings(mu=3, sigma=3, size=1000) array_2 = array_1 + DistributionSampling.generate_normal_samplings( mu=0, sigma=1, size=1000) array_3 = array_1 + DistributionSampling.generate_normal_samplings( mu=0.5, sigma=3, size=1000) # 检查双侧结果 self.assertTrue( StudentTTestRelatedTwoVariables( array_1, array_2, 0.05, TTestAlternative.TWO_SIDED).test().condition_satisfied) self.assertTrue( StudentTTestRelatedTwoVariables( array_1, array_3, 0.05, TTestAlternative.TWO_SIDED).test().condition_satisfied)
def test_normal_distribution_test(self): # 检查数据少于50正态分布是否为正态分布 self.assertTrue( NormalDistributionTest.test_normal_distribution( DistributionSampling(seed=1).generate_normal_samplings( 3, 5, 30))) # 检查数据50-300正态分布是否为正态分布 self.assertTrue( NormalDistributionTest.test_normal_distribution( DistributionSampling(seed=2).generate_normal_samplings( 3, 5, 200))) # 检查数据大于300正态分布是否为正态分布 self.assertTrue( NormalDistributionTest.test_normal_distribution( DistributionSampling(seed=3).generate_normal_samplings( 3, 5, 1000))) # 检查数据小于50指数分布是否不是正态分布 self.assertTrue(not NormalDistributionTest.test_normal_distribution( DistributionSampling(seed=4).generate_exponential_samplings( size=30))) # 检查数据50-300指数分布是否不是正态分布 self.assertTrue(not NormalDistributionTest.test_normal_distribution( DistributionSampling(seed=5).generate_exponential_samplings( size=200))) # 检查数据大于300指数分布是否不是正态分布 self.assertTrue(not NormalDistributionTest.test_normal_distribution( DistributionSampling(seed=6).generate_exponential_samplings( size=1000)))