def decision_tree_test(): features, labels = data.sample_decision_tree_data() # build the tree dTree = decision_tree.DecisionTree() dTree.train(features, labels) # print print('Your decision tree: ') Utils.print_tree(dTree) print('My decision tree: ') print( 'branch 0{\n\tdeep: 0\n\tnum of samples for each class: 2 : 2 \n\tsplit by dim 0\n\tbranch 0->0{\n\t\tdeep: ' '1\n\t\tnum of samples for each class: 1 \n\t\tclass:0\n\t}\n\tbranch 0->1{\n\t\tdeep: 1\n\t\tnum of ' 'samples for each class: 1 : 1 \n\t\tsplit by dim 0\n\t\tbranch 0->1->0{\n\t\t\tdeep: 2\n\t\t\tnum of ' 'samples for each class: 1 \n\t\t\tclass:0\n\t\t}\n\t\tbranch 0->1->1{\n\t\t\tdeep: 2\n\t\t\tnum of ' 'samples for each class: 1 \n\t\t\tclass:1\n\t\t}\n\t}\n\tbranch 0->2{\n\t\tdeep: 1\n\t\tnum of ' 'samples for each class: 1 \n\t\tclass:1\n\t}\n}') # data X_test, y_test = data.sample_decision_tree_test() # testing y_est_test = dTree.predict(X_test) print('Your estimate test: ', y_est_test) print('My estimate test: ', [0, 0, 1])
def decision_tree_test(): features, labels = data.sample_decision_tree_data() # build the tree dTree = decision_tree.ID3() dTree.train(features, labels) # print print('Your decision tree: ') Utils.printTree(dTree) # data X_test, y_test = data.sample_decision_tree_test() # testing y_est_test = dTree.predict(X_test) print('Your estimate test: ', y_est_test)
def test_tree(): features, labels = data.sample_decision_tree_data() # build the tree dTree = decision_tree.DecisionTree() dTree.train(features, labels) # print Utils.print_tree(dTree) # data X_test, y_test = data.sample_decision_tree_test() # testing y_est_test = dTree.predict(X_test) test_accu = accuracy_score(y_est_test, y_test) print('test_accu', test_accu) Utils.reduced_error_prunning(dTree, X_test, y_test) y_est_test = dTree.predict(X_test) test_accu = accuracy_score(y_est_test, y_test) print('test_accu', test_accu)
from utils import NormalizationScaler, MinMaxScaler scaling_classes = { 'min_max_scale': MinMaxScaler, 'normalize': NormalizationScaler, } #best_model, best_k, best_function, best_scaler = model_selection_with_transformation(distance_funcs, scaling_classes, Xtrain, ytrain, Xval, yval) import data import hw1_dt as decision_tree import utils as Utils from sklearn.metrics import accuracy_score features, labels = data.sample_decision_tree_data() # build the tree dTree = decision_tree.DecisionTree() dTree.train(features, labels) # print Utils.print_tree(dTree) # data X_test, y_test = data.sample_decision_tree_test() # testing y_est_test = dTree.predict(X_test) test_accu = accuracy_score(y_est_test, y_test)