def dt2():
    dt = LearningDecisionTree(
        training_datafile=training_datafile2,
        csv_class_column_index=1,
        csv_columns_for_features=[2, 3, 4, 5, 6, 7],
        entropy_threshold=0.01,
        max_depth_desired=8,
        save_training_datafile=training_datafile3,
    )
    dt.get_training_data()
    dt.calculate_first_order_probabilities()
    dt.calculate_class_priors()
    #dt.show_training_data()
    root_node = dt.construct_decision_tree_classifier()
    return dt, root_node
#!/usr/bin/env python

## classify_by_asking_questions.py

import LearningDecisionTree

# training_datafile = "training_symbolic.csv"
training_datafile = "animals.csv"

dt = LearningDecisionTree.LearningDecisionTree(
    training_datafile=training_datafile,
    csv_class_column_index=1,
    csv_columns_for_features=[2, 3, 4, 5, 6],
    entropy_threshold=0.01,
    # max_depth_desired = 8,
)
dt.get_training_data()
dt.calculate_first_order_probabilities()
dt.calculate_class_priors()

#   UNCOMMENT THE FOLLOWING LINE if you would like to see the training
#   data that was read from the disk file:
#dt.show_training_data()

root_node = dt.construct_decision_tree_classifier()

#   UNCOMMENT THE FOLLOWING LINE if you would like to see the decision
#   tree displayed in your terminal window:
root_node.display_decision_tree("   ")

classification = dt.classify_by_asking_questions(root_node)
Beispiel #3
0
# animals.py
# By Ashley Hale
#
# Experiment with the animals.csv training set
import LearningDecisionTree
from LearningDecisionTree import *

if __name__ == '__main__':
    '''
    This test code assumes animals.csv exists in the current directory.
    '''
    dt = LearningDecisionTree(
        training_datafile="animals.csv",
        csv_class_column_index=2,
        csv_columns_for_features=[3, 4, 5, 6, 7, 8],
        entropy_threshold=0.01,
        max_depth_desired=8,
        # csv_cleanup_needed = 1,
        # save_training_datafile = "new_animals.csv",
        # debug1 = 'debug1',
    )

    # printBox is a helper function in the code above and is not needed
    # for anything in the LearningDecisionTree - it's just useful for printing
    printBox("Testing with training data file '%s'" % dt._training_datafile)

    # ALL of these calls need to be done to set up the decision tree, except
    # show_training_data.
    #
    # root_node will be of type DTNode:
    # https://engineering.purdue.edu/kak/distDT/DecisionTree-3.4.3.html#DTNode
    dt.get_training_data()  # Required