Пример #1
0
 def test_naive_discretisation_version2(self):
     breakpoints = ins.SupervisedBreakpoints(
         ['yes', 'no', 'yes', 'yes', 'yes', 'no', 'no', 'yes', 'yes'],
         [64, 65, 68, 69, 70, 71, 72, 72, 75])
     breakpoints.find_naive_v2(3)
     self.assertEqual(2, len(breakpoints))
     self.assertEqual([4, 7], breakpoints)
Пример #2
0
 def test_entropy_based_breakpoints(self):
     breakpoints = ins.SupervisedBreakpoints(
         ['yes', 'no', 'yes', 'yes', 'yes', 'no'],
         [19.0, 21.0, 25.0, 31.0, 34.0, 42.0])
     breakpoints.find_entropy_based_max_depth(2)
     self.assertEqual(2, len(breakpoints))
     self.assertEqual([4, 0], breakpoints.data)
Пример #3
0
 def test_breakpoints_in_class_membership(self):
     breakpoints = ins.SupervisedBreakpoints(
         ['yes', 'no', 'yes', 'yes', 'yes', 'no'],
         [19.0, 21.0, 25.0, 31.0, 34.0, 42.0])
     breakpoints = breakpoints.breakpoints_in_class_membership()
     self.assertEqual(3, len(breakpoints))
     self.assertEqual([0, 1, 4], breakpoints)
Пример #4
0
 def test_adjust_for_min_freq(self):
     breakpoints = ins.SupervisedBreakpoints(['yes', 'no', 'yes', 'yes', 'yes', 'no', 'no', 'yes', 'yes'], [64, 65, 68, 69, 70, 71, 72, 72, 75])
     breakpoints.find_naive()
     self.assertEqual(4, len(breakpoints))
     self.assertEqual([0, 1, 4, 7], breakpoints)
     
     breakpoints.adjust_for_min_freq(4)
     self.assertEqual(1, len(breakpoints))
     self.assertEqual([4], breakpoints)
Пример #5
0
 def test_ranges_from_breakpoints(self):
     brkpts = ins.SupervisedBreakpoints(['no', 'yes', 'yes', 'yes', 'yes', 'no'], [19.0, 21.0, 25.0, 31.0, 34.0, 42.0])
     brkpts.find_naive()
     ranges = brkpts.as_ranges()
     self.assertEqual(3, len(ranges))
     self.assertEqual(19.0, ranges[0].lower)
     self.assertEqual(20.0, ranges[0].upper)
     self.assertEqual(20.0, ranges[1].lower)
     self.assertEqual(38.0, ranges[1].upper)
     self.assertEqual(38.0, ranges[2].lower)
     self.assertEqual(42.000001, ranges[2].upper)
Пример #6
0
 def test_adjust_for_equal_values(self):
     attr_values = [4.2999999999999998, 4.4000000000000004, 4.4000000000000004, 4.4000000000000004, 4.5, 4.5999999999999996, 4.5999999999999996, 4.5999999999999996, 4.5999999999999996, 4.7000000000000002, 4.7000000000000002, 4.7999999999999998, 4.7999999999999998, 4.7999999999999998, 4.7999999999999998, 4.7999999999999998, 4.9000000000000004, 4.9000000000000004, 4.9000000000000004, 4.9000000000000004, 4.9000000000000004, 4.9000000000000004, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0999999999999996, 5.0999999999999996, 5.0999999999999996, 5.0999999999999996, 5.0999999999999996, 5.0999999999999996, 5.0999999999999996, 5.0999999999999996, 5.0999999999999996, 5.2000000000000002, 5.2000000000000002, 5.2000000000000002, 5.2000000000000002, 5.2999999999999998, 5.4000000000000004, 5.4000000000000004, 5.4000000000000004, 5.4000000000000004, 5.4000000000000004, 5.4000000000000004, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5999999999999996, 5.5999999999999996, 5.5999999999999996, 5.5999999999999996, 5.5999999999999996, 5.5999999999999996, 5.7000000000000002, 5.7000000000000002, 5.7000000000000002, 5.7000000000000002, 5.7000000000000002, 5.7000000000000002, 5.7000000000000002, 5.7000000000000002, 5.7999999999999998, 5.7999999999999998, 5.7999999999999998, 5.7999999999999998, 5.7999999999999998, 5.7999999999999998, 5.7999999999999998, 5.9000000000000004, 5.9000000000000004, 5.9000000000000004, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0999999999999996, 6.0999999999999996, 6.0999999999999996, 6.0999999999999996, 6.0999999999999996, 6.0999999999999996, 6.2000000000000002, 6.2000000000000002, 6.2000000000000002, 6.2000000000000002, 6.2999999999999998, 6.2999999999999998, 6.2999999999999998, 6.2999999999999998, 6.2999999999999998, 6.2999999999999998, 6.2999999999999998, 6.2999999999999998, 6.2999999999999998, 6.4000000000000004, 6.4000000000000004, 6.4000000000000004, 6.4000000000000004, 6.4000000000000004, 6.4000000000000004, 6.4000000000000004, 6.5, 6.5, 6.5, 6.5, 6.5, 6.5999999999999996, 6.5999999999999996, 6.7000000000000002, 6.7000000000000002, 6.7000000000000002, 6.7000000000000002, 6.7000000000000002, 6.7000000000000002, 6.7000000000000002, 6.7000000000000002, 6.7999999999999998, 6.7999999999999998, 6.7999999999999998, 6.9000000000000004, 6.9000000000000004, 6.9000000000000004, 6.9000000000000004, 7.0, 7.0999999999999996, 7.2000000000000002, 7.2000000000000002, 7.2000000000000002, 7.2999999999999998, 7.4000000000000004, 7.5999999999999996, 7.7000000000000002, 7.7000000000000002, 7.7000000000000002, 7.7000000000000002, 7.9000000000000004]
     klass_values = ['Iris-setosa', 'Iris-setosa', 'Iris-setosa', 'Iris-setosa', 'Iris-setosa', 'Iris-setosa', 'Iris-setosa', 'Iris-setosa', 'Iris-setosa', 'Iris-setosa', 'Iris-setosa', 'Iris-setosa', 'Iris-setosa', 'Iris-setosa', 'Iris-setosa', 'Iris-setosa', 'Iris-setosa', 'Iris-setosa', 'Iris-setosa', 'Iris-setosa', 'Iris-versicolor', 'Iris-virginica', 'Iris-setosa', 'Iris-setosa', 'Iris-setosa', 'Iris-setosa', 'Iris-setosa', 'Iris-setosa', 'Iris-setosa', 'Iris-setosa', 'Iris-versicolor', 'Iris-versicolor', 'Iris-setosa', 'Iris-setosa', 'Iris-setosa', 'Iris-setosa', 'Iris-setosa', 'Iris-setosa', 'Iris-setosa', 'Iris-setosa', 'Iris-versicolor', 'Iris-setosa', 'Iris-setosa', 'Iris-setosa', 'Iris-versicolor', 'Iris-setosa', 'Iris-setosa', 'Iris-setosa', 'Iris-setosa', 'Iris-setosa', 'Iris-setosa', 'Iris-versicolor', 'Iris-setosa', 'Iris-setosa', 'Iris-versicolor', 'Iris-versicolor', 'Iris-versicolor', 'Iris-versicolor', 'Iris-versicolor', 'Iris-versicolor', 'Iris-versicolor', 'Iris-versicolor', 'Iris-versicolor', 'Iris-versicolor', 'Iris-virginica', 'Iris-setosa', 'Iris-setosa', 'Iris-versicolor', 'Iris-versicolor', 'Iris-versicolor', 'Iris-versicolor', 'Iris-versicolor', 'Iris-virginica', 'Iris-setosa', 'Iris-versicolor', 'Iris-versicolor', 'Iris-versicolor', 'Iris-virginica', 'Iris-virginica', 'Iris-virginica', 'Iris-versicolor', 'Iris-versicolor', 'Iris-virginica', 'Iris-versicolor', 'Iris-versicolor', 'Iris-versicolor', 'Iris-versicolor', 'Iris-virginica', 'Iris-virginica', 'Iris-versicolor', 'Iris-versicolor', 'Iris-versicolor', 'Iris-versicolor', 'Iris-virginica', 'Iris-virginica', 'Iris-versicolor', 'Iris-versicolor', 'Iris-virginica', 'Iris-virginica', 'Iris-versicolor', 'Iris-versicolor', 'Iris-versicolor', 'Iris-virginica', 'Iris-virginica', 'Iris-virginica', 'Iris-virginica', 'Iris-virginica', 'Iris-virginica', 'Iris-versicolor', 'Iris-versicolor', 'Iris-virginica', 'Iris-virginica', 'Iris-virginica', 'Iris-virginica', 'Iris-virginica', 'Iris-versicolor', 'Iris-virginica', 'Iris-virginica', 'Iris-virginica', 'Iris-virginica', 'Iris-versicolor', 'Iris-versicolor', 'Iris-versicolor', 'Iris-versicolor', 'Iris-versicolor', 'Iris-virginica', 'Iris-virginica', 'Iris-virginica', 'Iris-virginica', 'Iris-virginica', 'Iris-versicolor', 'Iris-virginica', 'Iris-virginica', 'Iris-versicolor', 'Iris-virginica', 'Iris-virginica', 'Iris-virginica', 'Iris-versicolor', 'Iris-virginica', 'Iris-virginica', 'Iris-virginica', 'Iris-virginica', 'Iris-virginica', 'Iris-virginica', 'Iris-virginica', 'Iris-virginica', 'Iris-virginica', 'Iris-virginica', 'Iris-virginica', 'Iris-virginica']
     sb = ins.SupervisedBreakpoints(klass_values, attr_values)
     breakpoints = sb.breakpoints_in_class_membership()
     self.assertEqual([19, 20, 21, 29, 31, 39, 40, 43, 44, 50, 51, 53, 63, 64, 66, 71, 72, 73, 76, 79, 81, 82, 86, 88, 92, 94, 96, 98, 101, 107, 109, 114, 115, 119, 124, 129, 130, 132, 133, 136, 137], breakpoints)
     self.assertAlmostEqual(4.9, attr_values[19])
     self.assertAlmostEqual(4.9, attr_values[20])
     self.assertAlmostEqual(4.9, attr_values[21])
     self.assertAlmostEqual(5.0, attr_values[22])
     self.assertAlmostEqual(5.0, attr_values[29])
     self.assertAlmostEqual(5.0, attr_values[30])
     self.assertAlmostEqual(5.0, attr_values[31])
     self.assertAlmostEqual(5.1, attr_values[32])
     
     sb.find_naive()
     self.assertEqual([21, 31, 40, 44, 51, 58, 64, 72, 79, 82, 88, 94, 98, 107, 114, 119, 129, 132, 136, 137], sb.data)
     self.assertAlmostEqual(4.9, attr_values[sb[0]])
     self.assertAlmostEqual(5.0, attr_values[sb[1]])
     self.assertAlmostEqual(5.1, attr_values[sb[2]])