A Python module for constructing a decision tree from multidimensional training data and for using the decision tree for classifying unlabeled data
Project description
Version 1.7 This version includes safety checks on the consistency of the data you place in your training datafile. When a training file contains thousands of samples, it is difficult to manually check that you used the same class names in your sample records that you declared at the top of your training file or that the values you have for your features are legal in light of the earlier declarations regarding such values in the training file. Another safety feature incorporated in this version is the non-consideration of classes that are declared at the top of the training file but that have no sample records in the file.
Assuming you have arranged your training data in the form of a table in a text file, all you have to do is to supply the name of the training datafile to this module and it does the rest for you without much effort on your part. A decision tree classifier consists of feature tests that are arranged in the form of a tree. The feature test associated with the root node is one that can be expected to maximally disambiguate the different possible class labels for an unlabeled data record. From the root node hangs a set of child nodes, one for each value of the feature at the root node. At each such child node, a feature test is selected that is the most class discriminative given that you have already applied the feature test at the root node and observed the value for that feature. This process is continued until you reach the leaf nodes of the tree. The leaf nodes may either correspond to the maximum depth desired for the decision tree or to the case when you run out of features to test.
Typical usage syntax:
dt = DecisionTree( training_datafile = “training.dat” )
dt.get_training_data()
dt.show_training_data()
root_node = dt.construct_decision_tree_classifier()
root_node.display_decision_tree(” “)
- test_sample = [‘exercising=>never’, ‘smoking=>heavy’,
‘fatIntake=>heavy’, ‘videoAddiction=>heavy’]
classification = dt.classify(root_node, test_sample)
print “Classification: “, classification