weka.classifiers.j48
Class J48

java.lang.Object
  |
  +--weka.classifiers.Classifier
        |
        +--weka.classifiers.DistributionClassifier
              |
              +--weka.classifiers.j48.J48
All Implemented Interfaces:
AdditionalMeasureProducer, java.lang.Cloneable, Drawable, Matchable, OptionHandler, java.io.Serializable, Sourcable, Summarizable, WeightedInstancesHandler

public class J48
extends DistributionClassifier
implements OptionHandler, Drawable, Matchable, Sourcable, WeightedInstancesHandler, Summarizable, AdditionalMeasureProducer

Class for generating an unpruned or a pruned C4.5 decision tree. For more information, see

Ross Quinlan (1993). C4.5: Programs for Machine Learning, Morgan Kaufmann Publishers, San Mateo, CA.

Valid options are:

-U
Use unpruned tree.

-C confidence
Set confidence threshold for pruning. (Default: 0.25)

-M number
Set minimum number of instances per leaf. (Default: 2)

-R
Use reduced error pruning. No subtree raising is performed.

-N number
Set number of folds for reduced error pruning. One fold is used as the pruning set. (Default: 3)

-B
Use binary splits for nominal attributes.

-S
Don't perform subtree raising.

-L
Do not clean up after the tree has been built.

-A
If set, Laplace smoothing is used for predicted probabilites.

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

Constructor Summary
J48()
           
 
Method Summary
 void buildClassifier(Instances instances)
          Generates the classifier.
 double classifyInstance(Instance instance)
          Classifies an instance.
 double[] distributionForInstance(Instance instance)
          Returns class probabilities for an instance.
 java.util.Enumeration enumerateMeasures()
          Returns an enumeration of the additional measure names
 boolean getBinarySplits()
          Get the value of binarySplits.
 float getConfidenceFactor()
          Get the value of CF.
 double getMeasure(java.lang.String additionalMeasureName)
          Returns the value of the named measure
 int getMinNumObj()
          Get the value of minNumObj.
 int getNumFolds()
          Get the value of numFolds.
 java.lang.String[] getOptions()
          Gets the current settings of the Classifier.
 boolean getReducedErrorPruning()
          Get the value of reducedErrorPruning.
 boolean getSaveInstanceData()
          Check whether instance data is to be saved.
 boolean getSubtreeRaising()
          Get the value of subtreeRaising.
 boolean getUnpruned()
          Get the value of unpruned.
 boolean getUseLaplace()
          Get the value of useLaplace.
 java.lang.String graph()
          Returns graph describing the tree.
 java.util.Enumeration listOptions()
          Returns an enumeration describing the available options Valid options are:
static void main(java.lang.String[] argv)
          Main method for testing this class
 double measureNumLeaves()
          Returns the number of leaves
 double measureNumRules()
          Returns the number of rules (same as number of leaves)
 double measureTreeSize()
          Returns the size of the tree
 java.lang.String prefix()
          Returns tree in prefix order.
 void setBinarySplits(boolean v)
          Set the value of binarySplits.
 void setConfidenceFactor(float v)
          Set the value of CF.
 void setMinNumObj(int v)
          Set the value of minNumObj.
 void setNumFolds(int v)
          Set the value of numFolds.
 void setOptions(java.lang.String[] options)
          Parses a given list of options.
 void setReducedErrorPruning(boolean v)
          Set the value of reducedErrorPruning.
 void setSaveInstanceData(boolean v)
          Set whether instance data is to be saved.
 void setSubtreeRaising(boolean v)
          Set the value of subtreeRaising.
 void setUnpruned(boolean v)
          Set the value of unpruned.
 void setUseLaplace(boolean newuseLaplace)
          Set the value of useLaplace.
 java.lang.String toSource(java.lang.String className)
          Returns tree as an if-then statement.
 java.lang.String toString()
          Returns a description of the classifier.
 java.lang.String toSummaryString()
          Returns a superconcise version of the model
 
Methods inherited from class weka.classifiers.Classifier
forName, makeCopies
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

J48

public J48()
Method Detail

buildClassifier

public void buildClassifier(Instances instances)
                     throws java.lang.Exception
Generates the classifier.
Overrides:
buildClassifier in class Classifier
Throws:
java.lang.Exception - if classifier can't be built successfully

classifyInstance

public double classifyInstance(Instance instance)
                        throws java.lang.Exception
Classifies an instance.
Overrides:
classifyInstance in class DistributionClassifier
Throws:
java.lang.Exception - if instance can't be classified successfully

distributionForInstance

public final double[] distributionForInstance(Instance instance)
                                       throws java.lang.Exception
Returns class probabilities for an instance.
Overrides:
distributionForInstance in class DistributionClassifier
Throws:
java.lang.Exception - if distribution can't be computed successfully

graph

public java.lang.String graph()
                       throws java.lang.Exception
Returns graph describing the tree.
Specified by:
graph in interface Drawable
Throws:
java.lang.Exception - if graph can't be computed

prefix

public java.lang.String prefix()
                        throws java.lang.Exception
Returns tree in prefix order.
Specified by:
prefix in interface Matchable
Throws:
java.lang.Exception - if something goes wrong

toSource

public java.lang.String toSource(java.lang.String className)
                          throws java.lang.Exception
Returns tree as an if-then statement.
Specified by:
toSource in interface Sourcable
Returns:
the tree as a Java if-then type statement
Throws:
java.lang.Exception - if something goes wrong

listOptions

public java.util.Enumeration listOptions()
Returns an enumeration describing the available options Valid options are:

-U
Use unpruned tree.

-C confidence
Set confidence threshold for pruning. (Default: 0.25)

-M number
Set minimum number of instances per leaf. (Default: 2)

-R
Use reduced error pruning. No subtree raising is performed.

-N number
Set number of folds for reduced error pruning. One fold is used as the pruning set. (Default: 3)

-B
Use binary splits for nominal attributes.

-S
Don't perform subtree raising.

-L
Do not clean up after the tree has been built. -A
If set, Laplace smoothing is used for predicted probabilites.

Specified by:
listOptions in interface OptionHandler
Returns:
an enumeration of all the available options

setOptions

public void setOptions(java.lang.String[] options)
                throws java.lang.Exception
Parses a given list of options.
Specified by:
setOptions in interface OptionHandler
Parameters:
options - the list of options as an array of strings
Throws:
java.lang.Exception - if an option is not supported

getOptions

public java.lang.String[] getOptions()
Gets the current settings of the Classifier.
Specified by:
getOptions in interface OptionHandler
Returns:
an array of strings suitable for passing to setOptions

getUseLaplace

public boolean getUseLaplace()
Get the value of useLaplace.
Returns:
Value of useLaplace.

setUseLaplace

public void setUseLaplace(boolean newuseLaplace)
Set the value of useLaplace.
Parameters:
newuseLaplace - Value to assign to useLaplace.

toString

public java.lang.String toString()
Returns a description of the classifier.
Overrides:
toString in class java.lang.Object

toSummaryString

public java.lang.String toSummaryString()
Returns a superconcise version of the model
Specified by:
toSummaryString in interface Summarizable
Following copied from interface: weka.core.Summarizable
Returns:
the object summarized as a string

measureTreeSize

public double measureTreeSize()
Returns the size of the tree
Returns:
the size of the tree

measureNumLeaves

public double measureNumLeaves()
Returns the number of leaves
Returns:
the number of leaves

measureNumRules

public double measureNumRules()
Returns the number of rules (same as number of leaves)
Returns:
the number of rules

enumerateMeasures

public java.util.Enumeration enumerateMeasures()
Returns an enumeration of the additional measure names
Specified by:
enumerateMeasures in interface AdditionalMeasureProducer
Returns:
an enumeration of the measure names

getMeasure

public double getMeasure(java.lang.String additionalMeasureName)
Returns the value of the named measure
Specified by:
getMeasure in interface AdditionalMeasureProducer
Parameters:
measureName - the name of the measure to query for its value
Returns:
the value of the named measure
Throws:
java.lang.IllegalArgumentException - if the named measure is not supported

getUnpruned

public boolean getUnpruned()
Get the value of unpruned.
Returns:
Value of unpruned.

setUnpruned

public void setUnpruned(boolean v)
Set the value of unpruned. Turns reduced-error pruning off if set.
Parameters:
v - Value to assign to unpruned.

getConfidenceFactor

public float getConfidenceFactor()
Get the value of CF.
Returns:
Value of CF.

setConfidenceFactor

public void setConfidenceFactor(float v)
Set the value of CF.
Parameters:
v - Value to assign to CF.

getMinNumObj

public int getMinNumObj()
Get the value of minNumObj.
Returns:
Value of minNumObj.

setMinNumObj

public void setMinNumObj(int v)
Set the value of minNumObj.
Parameters:
v - Value to assign to minNumObj.

getReducedErrorPruning

public boolean getReducedErrorPruning()
Get the value of reducedErrorPruning.
Returns:
Value of reducedErrorPruning.

setReducedErrorPruning

public void setReducedErrorPruning(boolean v)
Set the value of reducedErrorPruning. Turns unpruned trees off if set.
Parameters:
v - Value to assign to reducedErrorPruning.

getNumFolds

public int getNumFolds()
Get the value of numFolds.
Returns:
Value of numFolds.

setNumFolds

public void setNumFolds(int v)
Set the value of numFolds.
Parameters:
v - Value to assign to numFolds.

getBinarySplits

public boolean getBinarySplits()
Get the value of binarySplits.
Returns:
Value of binarySplits.

setBinarySplits

public void setBinarySplits(boolean v)
Set the value of binarySplits.
Parameters:
v - Value to assign to binarySplits.

getSubtreeRaising

public boolean getSubtreeRaising()
Get the value of subtreeRaising.
Returns:
Value of subtreeRaising.

setSubtreeRaising

public void setSubtreeRaising(boolean v)
Set the value of subtreeRaising.
Parameters:
v - Value to assign to subtreeRaising.

getSaveInstanceData

public boolean getSaveInstanceData()
Check whether instance data is to be saved.
Returns:
true if instance data is saved

setSaveInstanceData

public void setSaveInstanceData(boolean v)
Set whether instance data is to be saved.
Parameters:
v - true if instance data is to be saved

main

public static void main(java.lang.String[] argv)
Main method for testing this class
Parameters:
String - options