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])
Example #2
0
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)
Example #3
0
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)
Example #4
0
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)
print('test_accu', test_accu)
"""

"""
#load data
X_train, y_train, X_test, y_test = data.load_decision_tree_data()

# set classifier
dTree = decision_tree.DecisionTree()