Class DecisionTree

java.lang.Object
  extended by DecisionTree
Direct Known Subclasses:
DecisionTreeInternal, DecisionTreeLeaf

public abstract class DecisionTree
extends java.lang.Object

A DecisionTree object represents a decision tree, as described in, for example, the book "Artificial Intelligence" by Russell and Norvig (3rd edition). A DecisionTree is constructed using a set of training examples, and is capable of deciding the class of a novel example. Because decision trees are recursive data structures, any given DecisionTree object could be a node in a larger decision tree, referred to as the full decision tree in the documentation below.

Author:
jmac

Field Summary
static java.lang.String ROOT_LABEL
          The label assigned to the root node of a decision tree.
 
Method Summary
 double computeErrorRate(InstanceSet testSet)
          Compute the error rate of the decision tree on the given test set.
static DecisionTree constructDecisionTree(InstanceSet examples, java.util.ArrayList<Attribute> attributes, InstanceSet parentExamples, java.lang.String label, int depth)
          Construct a decision tree according to the recursive algorithm given in figure 18.5 of Russell and Norvig (third edition).
abstract  java.lang.String decide(AttributeSet attributes, Instance instance)
          Return the decision tree's decision for the given instance: that is, the classification that should be assigned to the instance.
static void main(java.lang.String[] arguments)
          Constructs a decision tree from the data in a .arff file, prints out the tree, the error rate on the training set, and the decisions on each instance in the training set.
 void print()
          Print out the DecisionTree in a human-readable form
 void printDecisions(InstanceSet testSet)
          Print out the decision of this decision tree on every instance in the given test set.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ROOT_LABEL

public static final java.lang.String ROOT_LABEL
The label assigned to the root node of a decision tree.

See Also:
Constant Field Values
Method Detail

constructDecisionTree

public static DecisionTree constructDecisionTree(InstanceSet examples,
                                                 java.util.ArrayList<Attribute> attributes,
                                                 InstanceSet parentExamples,
                                                 java.lang.String label,
                                                 int depth)
                                          throws DecisionTreeException
Construct a decision tree according to the recursive algorithm given in figure 18.5 of Russell and Norvig (third edition).

Parameters:
examples - The examples from which this tree should be learned.
attributes - A list of attributes on which this tree is permitted to make decisions.
parentExamples - The examples from which the parent node of this DecisionTree object were learned. to construct the root node, parentExamples should be null.
label - The label on the edge leading to this DecisionTree node, or DecisionTree.ROOT_LABEL for the root.
depth - The depth of this node in the full decision tree.
Returns:
The constructed DecisionTree.
Throws:
DecisionTreeException

decide

public abstract java.lang.String decide(AttributeSet attributes,
                                        Instance instance)
Return the decision tree's decision for the given instance: that is, the classification that should be assigned to the instance.

Parameters:
attributes - The set of attributes employed by the instance.
instance - The instance to be classified.
Returns:
The classification of the given instance.

print

public void print()
Print out the DecisionTree in a human-readable form


computeErrorRate

public double computeErrorRate(InstanceSet testSet)
Compute the error rate of the decision tree on the given test set.

Parameters:
testSet - A set of examples on which the error rate will be computed.
Returns:
The error rate of the decision tree on the given test set.

printDecisions

public void printDecisions(InstanceSet testSet)
Print out the decision of this decision tree on every instance in the given test set.

Parameters:
testSet - The set of instances whose decisions will be printed.

main

public static void main(java.lang.String[] arguments)
                 throws DecisionTreeException,
                        java.io.FileNotFoundException,
                        java.io.IOException
Constructs a decision tree from the data in a .arff file, prints out the tree, the error rate on the training set, and the decisions on each instance in the training set.

Parameters:
arguments - Requires a single command line argument, what should be the name of a data file in .arff format.
Throws:
DecisionTreeException
java.io.FileNotFoundException
java.io.IOException