22import unittest
33
44import numpy as np
5- from numpy .testing import assert_almost_equal
65from sklearn import datasets
76
87from supervised import AutoML
2019
2120class AutoMLSampleWeightTest (unittest .TestCase ):
2221 automl_dir = "AutoMLSampleWeightTest"
22+ score_tolerance = 0.1
2323
2424 def tearDown (self ):
2525 shutil .rmtree (self .automl_dir , ignore_errors = True )
2626
27+ def assert_score_close (self , score_1 , score_2 ):
28+ self .assertLessEqual (abs (score_1 - score_2 ), self .score_tolerance )
29+
2730 def test_iris_dataset_sample_weight (self ):
2831 """Tests AutoML in the iris dataset (Multiclass classification)
2932 without and with sample weight"""
@@ -41,7 +44,7 @@ def test_iris_dataset_sample_weight(self):
4144 score_2 = model .fit (iris .data , iris .target , sample_weight = sample_weight ).score (
4245 iris .data , iris .target , sample_weight = sample_weight
4346 )
44- assert_almost_equal (score_1 , score_2 )
47+ self . assert_score_close (score_1 , score_2 )
4548
4649 def test_housing_dataset (self ):
4750 """Tests AutoML in the housing dataset (Regression)
@@ -62,7 +65,7 @@ def test_housing_dataset(self):
6265 score_2 = model .fit (
6366 housing [0 ], housing [1 ], sample_weight = sample_weight
6467 ).score (housing [0 ], housing [1 ], sample_weight = sample_weight )
65- assert_almost_equal (score_1 , score_2 )
68+ self . assert_score_close (score_1 , score_2 )
6669
6770 def test_breast_cancer_dataset (self ):
6871 """Tests AutoML in the breast cancer (binary classification)
@@ -83,4 +86,4 @@ def test_breast_cancer_dataset(self):
8386 score_2 = model .fit (
8487 breast_cancer .data , breast_cancer .target , sample_weight = sample_weight
8588 ).score (breast_cancer .data , breast_cancer .target , sample_weight = sample_weight )
86- assert_almost_equal (score_1 , score_2 )
89+ self . assert_score_close (score_1 , score_2 )
0 commit comments