weka.classifiers.trees
Class Id3

java.lang.Object
  extended byweka.classifiers.Classifier
      extended byweka.classifiers.trees.Id3
All Implemented Interfaces:
java.lang.Cloneable, OptionHandler, java.io.Serializable

public class Id3
extends Classifier

Class implementing an Id3 decision tree classifier. For more information, see

R. Quinlan (1986). Induction of decision trees. Machine Learning. Vol.1, No.1, pp. 81-106.

Version:
$Revision: 1.11 $
Author:
Eibe Frank (eibe@cs.waikato.ac.nz)
See Also:
Serialized Form

Field Summary
private  Attribute m_Attribute
          Attribute used for splitting.
private  Attribute m_ClassAttribute
          Class attribute of dataset.
private  double m_ClassValue
          Class value if node is leaf.
private  double[] m_Distribution
          Class distribution if node is leaf.
private  Id3[] m_Successors
          The node's successors.
 
Fields inherited from class weka.classifiers.Classifier
m_Debug
 
Constructor Summary
Id3()
           
 
Method Summary
 void buildClassifier(Instances data)
          Builds Id3 decision tree classifier.
 double classifyInstance(Instance instance)
          Classifies a given test instance using the decision tree.
private  double computeEntropy(Instances data)
          Computes the entropy of a dataset.
private  double computeInfoGain(Instances data, Attribute att)
          Computes information gain for an attribute.
 double[] distributionForInstance(Instance instance)
          Computes class distribution for instance using decision tree.
 java.lang.String globalInfo()
          Returns a string describing classifier
static void main(java.lang.String[] args)
          Main method.
private  void makeTree(Instances data)
          Method building Id3 tree.
private  Instances[] splitData(Instances data, Attribute att)
          Splits a dataset according to the values of a nominal attribute.
 java.lang.String toString()
          Prints the decision tree using the private toString method from below.
private  java.lang.String toString(int level)
          Outputs a tree at a certain level.
 
Methods inherited from class weka.classifiers.Classifier
debugTipText, forName, getDebug, getOptions, listOptions, makeCopies, setDebug, setOptions
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

m_Successors

private Id3[] m_Successors
The node's successors.


m_Attribute

private Attribute m_Attribute
Attribute used for splitting.


m_ClassValue

private double m_ClassValue
Class value if node is leaf.


m_Distribution

private double[] m_Distribution
Class distribution if node is leaf.


m_ClassAttribute

private Attribute m_ClassAttribute
Class attribute of dataset.

Constructor Detail

Id3

public Id3()
Method Detail

globalInfo

public java.lang.String globalInfo()
Returns a string describing classifier

Returns:
a description suitable for displaying in the explorer/experimenter gui

buildClassifier

public void buildClassifier(Instances data)
                     throws java.lang.Exception
Builds Id3 decision tree classifier.

Specified by:
buildClassifier in class Classifier
Parameters:
data - the training data
Throws:
java.lang.Exception - if classifier can't be built successfully

makeTree

private void makeTree(Instances data)
               throws java.lang.Exception
Method building Id3 tree.

Parameters:
data - the training data
Throws:
java.lang.Exception - if decision tree can't be built successfully

classifyInstance

public double classifyInstance(Instance instance)
Classifies a given test instance using the decision tree.

Overrides:
classifyInstance in class Classifier
Parameters:
instance - the instance to be classified
Returns:
the classification

distributionForInstance

public double[] distributionForInstance(Instance instance)
Computes class distribution for instance using decision tree.

Overrides:
distributionForInstance in class Classifier
Parameters:
instance - the instance for which distribution is to be computed
Returns:
the class distribution for the given instance

toString

public java.lang.String toString()
Prints the decision tree using the private toString method from below.

Returns:
a textual description of the classifier

computeInfoGain

private double computeInfoGain(Instances data,
                               Attribute att)
                        throws java.lang.Exception
Computes information gain for an attribute.

Parameters:
data - the data for which info gain is to be computed
att - the attribute
Returns:
the information gain for the given attribute and data
Throws:
java.lang.Exception

computeEntropy

private double computeEntropy(Instances data)
                       throws java.lang.Exception
Computes the entropy of a dataset.

Parameters:
data - the data for which entropy is to be computed
Returns:
the entropy of the data's class distribution
Throws:
java.lang.Exception

splitData

private Instances[] splitData(Instances data,
                              Attribute att)
Splits a dataset according to the values of a nominal attribute.

Parameters:
data - the data which is to be split
att - the attribute to be used for splitting
Returns:
the sets of instances produced by the split

toString

private java.lang.String toString(int level)
Outputs a tree at a certain level.

Parameters:
level - the level at which the tree is to be printed

main

public static void main(java.lang.String[] args)
Main method.

Parameters:
args - the options for the classifier