def same_val_test(self): test_obj = Decision_Tree_Classifier() test_data = [1, 1, 2] test_data2 = [1, 1, 1] return self.is_true(test_obj.is_same_value( test_data2)) and not test_obj.is_same_value(test_data)
def best_feature_test(self): test_obj = Decision_Tree_Classifier() test_array, test_target = self.setup_data() at, d_l, t_l, d_r, t_r = test_obj.find_best_gain( test_array, test_target) return 0
def comprehensive_tree_test(self): program = Tests() program.execute_option("ld") test_obj = Decision_Tree_Classifier() test_data, test_target = program.training_data_to_list() tree_root = test_obj.build_tree_2(test_data, test_target) test_obj.print_tree(tree_root) return 0
def split_data_test(self): testObj = Decision_Tree_Classifier() target_data = [0, 0, 0, 1, 1, 1] test_data = [[1], [2], [3], [4], [5], [6]] attribute = 4 left_data, left_target, right_data, right_target = testObj.split_data( 0, test_data, target_data, attribute) return self.is_true(left_target == [0, 0, 0]) and left_data == [[1], [ 2 ], [3]] and right_target == [1, 1, 1] and right_data == [[4], [5], [6]]
def attribute_test(self): testObj = Decision_Tree_Classifier() test_data = [[0, 1, 2], [1, 1, 2], [2, 1, 2], [3, 1, 2], [4, 1, 2], [5, 1, 2]] expected_1 = 3 actual_1 = testObj.get_attritube(0, test_data) test_data = [[1, 1, 2], [0, 2, 3], [1, 2, 3]] actual_2 = testObj.get_attritube(0, test_data) expected_2 = 1 return self.is_equal(actual_1, expected_1) and self.is_equal( actual_2, expected_2)
def entropy_test(self): testObj = Decision_Tree_Classifier() actual = testObj.entropy([5, 9]) #Entropy Test P1= 5/14, P2 = 9/14, Expected = 0.9403, actual: ", actual) return self.is_equal(0.9403, actual)
def most_common_test(self): test_obj = Decision_Tree_Classifier() test_data = [1, 2, 3, 3, 2, 3] actual = test_obj.most_common(test_data) return self.is_equal(3, actual)
def build_tree_test(self): test_obj = Decision_Tree_Classifier() test_data, test_target = self.setup_data() tree_root = test_obj.build_tree_2(test_data, test_target) return 0
def column_tree_entropy_test(self): testObj = Decision_Tree_Classifier() actual = testObj.feature_entropy( [0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0]) return self.is_equal(0.9403, actual)
def remove_feature_test(self): test_array, test_target = self.setup_data() testObj = Decision_Tree_Classifier() test_array = testObj.remove_feature(test_array, 0) return self.is_true(test_array == [[3, 6], [2, 5], [4, 8], [2, 5]])