Package weka.classifiers.trees

# Class J48graft

java.lang.Object
weka.classifiers.Classifier
weka.classifiers.trees.J48graft

All Implemented Interfaces:
  `Serializable`, `Cloneable`, `Sourcable`, `AdditionalMeasureProducer`, `CapabilitiesHandler`, `Drawable`, `Matchable`, `OptionHandler`, `RevisionHandler`, `Summarizable`, `TechnicalInformationHandler`, `WeightedInstancesHandler`

public class J48graft extends Classifier implements OptionHandler, Drawable, Matchable, Sourcable, WeightedInstancesHandler, Summarizable, AdditionalMeasureProducer, TechnicalInformationHandler
Class for generating a grafted (pruned or unpruned) C4.5 decision tree. For more information, see
Geoff Webb: Decision Tree Grafting From the All-Tests-But-One Partition. In: , San Francisco, CA, 1999.

BibTeX:

     @inproceedings{Webb1999,
        address = {San Francisco, CA},
        author = {Geoff Webb},
        publisher = {Morgan Kaufmann},
        title = {Decision Tree Grafting From the All-Tests-But-One Partition},
        year = {1999}
     }

Valid options are:

     -U
      Use unpruned tree.

     -C <pruning confidence>
      Set confidence threshold for pruning.
      (default 0.25)

     -M <minimum number of instances>
      Set minimum number of instances per leaf.
      (default 2)

     -B
      Use binary splits only.

     -S
      Don't perform subtree raising.

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

     -A
      Laplace smoothing for predicted probabilities.  (note: this option only affects initial tree; grafting process always uses laplace).

     -E
      Relabel when grafting.

Version:
  $Revision: 5535 $
Author:
  Janice Boughton (jrbought@csse.monash.edu.au) (based on J48.java written by Eibe Frank)
See Also:
  - Serialized Form

## Field Summary

### Fields inherited from interface weka.core.Drawable

`BayesNet, Newick, NOT_DRAWABLE, TREE`

## Constructor Summary

Constructors
Constructor
Description
`J48graft()`

## Method Summary

Modifier and Type
Method
Description
`String`
`binarySplitsTipText()`
Returns the tip text for this property
`void`
`buildClassifier(Instances instances)`
Generates the classifier.
`double`
`classifyInstance(Instance instance)`
Classifies an instance.
`String`
`confidenceFactorTipText()`
Returns the tip text for this property
`final double[]`
`distributionForInstance(Instance instance)`
Returns class probabilities for an instance.
`Enumeration`
`enumerateMeasures()`
Returns an enumeration of the additional measure names
`boolean`
`getBinarySplits()`
Get the value of binarySplits.
`Capabilities`
`getCapabilities()`
Returns default capabilities of the classifier.
`float`
`getConfidenceFactor()`
Get the value of CF.
`double`
`getMeasure(String additionalMeasureName)`
Returns the value of the named measure
`int`
`getMinNumObj()`
Get the value of minNumObj.
`String[]`
`getOptions()`
Gets the current settings of the Classifier.
`boolean`
`getRelabel()`
Get the value of relabelling
`String`
`getRevision()`
Returns the revision string.
`boolean`
`getSaveInstanceData()`
Check whether instance data is to be saved.
`boolean`
`getSubtreeRaising()`
Get the value of subtreeRaising.
`TechnicalInformation`
`getTechnicalInformation()`
Returns an instance of a TechnicalInformation object, containing detailed information about the technical background of this class, e.g., paper reference or book this class is based on.
`boolean`
`getUnpruned()`
Get the value of unpruned.
`boolean`
`getUseLaplace()`
Get the value of useLaplace.
`String`
`globalInfo()`
Returns a string describing classifier
`String`
`graph()`
Returns graph describing the tree.
`int`
`graphType()`
Returns the type of graph this classifier represents.
`Enumeration`
`listOptions()`
Returns an enumeration describing the available options.
`static void`
`main(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
`String`
`minNumObjTipText()`
Returns the tip text for this property
`String`
`prefix()`
Returns tree in prefix order.
`String`
`relabelTipText()`
Returns the tip text for this property
`String`
`saveInstanceDataTipText()`
Returns the tip text for this property
`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`
`setOptions(String[] options)`
Parses a given list of options.
`void`
`setRelabel(boolean v)`
Set the value of relabelling.
`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.
`String`
`subtreeRaisingTipText()`
Returns the tip text for this property
`String`
`toSource(String className)`
Returns tree as an if-then statement.
`String`
`toString()`
Returns a description of the classifier.
`String`
`toSummaryString()`
Returns a superconcise version of the model
`String`
`unprunedTipText()`
Returns the tip text for this property
`String`
`useLaplaceTipText()`
Returns the tip text for this property

### Methods inherited from class weka.classifiers.Classifier

`debugTipText, forName, getDebug, makeCopies, makeCopy, setDebug`

### Methods inherited from class java.lang.Object

`equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

## Constructor Details

### J48graft

public J48graft()

## Method Details

### globalInfo

public String globalInfo()
Returns a string describing classifier

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

### getTechnicalInformation

public TechnicalInformation getTechnicalInformation()
Returns an instance of a TechnicalInformation object, containing detailed information about the technical background of this class, e.g., paper reference or book this class is based on.

Specified by:
  `getTechnicalInformation` in interface `TechnicalInformationHandler`
Returns:
  the technical information about this class

### getCapabilities

public Capabilities getCapabilities()
Returns default capabilities of the classifier.

Specified by:
  `getCapabilities` in interface `CapabilitiesHandler`
Overrides:
  `getCapabilities` in class `Classifier`
Returns:
  the capabilities of this classifier
See Also:
  - `Capabilities`

### buildClassifier

public void buildClassifier(Instances instances) throws Exception
Generates the classifier.

Specified by:
  `buildClassifier` in class `Classifier`
Parameters:
  `instances` - the data to train the classifier with
Throws:
  `Exception` - if classifier can't be built successfully

### classifyInstance

public double classifyInstance(Instance instance) throws Exception
Classifies an instance.

Overrides:
  `classifyInstance` in class `Classifier`
Parameters:
  `instance` - the instance to classify
Returns:
  the classification for the instance
Throws:
  `Exception` - if instance can't be classified successfully

### distributionForInstance

public final double[] distributionForInstance(Instance instance) throws Exception
Returns class probabilities for an instance.

Overrides:
  `distributionForInstance` in class `Classifier`
Parameters:
  `instance` - the instance to calculate the class probabilities for
Returns:
  the class probabilities
Throws:
  `Exception` - if distribution can't be computed successfully

### graphType

public int graphType()
Returns the type of graph this classifier represents.

Specified by:
  `graphType` in interface `Drawable`
Returns:
  Drawable.TREE

### graph

public String graph() throws Exception
Returns graph describing the tree.

Specified by:
  `graph` in interface `Drawable`
Returns:
  the graph describing the tree
Throws:
  `Exception` - if graph can't be computed

### prefix

public String prefix() throws Exception
Returns tree in prefix order.

Specified by:
  `prefix` in interface `Matchable`
Returns:
  the tree in prefix order
Throws:
  `Exception` - if something goes wrong

### toSource

public String toSource(String className) throws Exception
Returns tree as an if-then statement.

Specified by:
  `toSource` in interface `Sourcable`
Parameters:
  `className` - the name of the Java class
Returns:
  the tree as a Java if-then type statement
Throws:
  `Exception` - if something goes wrong

### listOptions

public 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)

-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. (note: this option only affects initial tree; grafting process always uses laplace).

-E
Allow relabelling when grafting.

Specified by:
  `listOptions` in interface `OptionHandler`
Overrides:
  `listOptions` in class `Classifier`
Returns:
  an enumeration of all the available options.

### setOptions

public void setOptions(String[] options) throws Exception
Parses a given list of options. Valid options are:

     -U
      Use unpruned tree.

     -C <pruning confidence>
      Set confidence threshold for pruning.
      (default 0.25)

     -M <minimum number of instances>
      Set minimum number of instances per leaf.
      (default 2)

     -B
      Use binary splits only.

     -S
      Don't perform subtree raising.

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

     -A
      Laplace smoothing for predicted probabilities.  (note: this option only affects initial tree; grafting process always uses laplace).

     -E
      Relabel when grafting.

Specified by:
  `setOptions` in interface `OptionHandler`
Overrides:
  `setOptions` in class `Classifier`
Parameters:
  `options` - the list of options as an array of strings
Throws:
  `Exception` - if an option is not supported

### getOptions

public String[] getOptions()
Gets the current settings of the Classifier.

Specified by:
  `getOptions` in interface `OptionHandler`
Overrides:
  `getOptions` in class `Classifier`
Returns:
  an array of strings suitable for passing to setOptions

### useLaplaceTipText

public String useLaplaceTipText()
Returns the tip text for this property

Returns:
  tip text for this property suitable for displaying in the explorer/experimenter gui

### 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 String toString()
Returns a description of the classifier.

Overrides:
  `toString` in class `Object`
Returns:
  a description of the classifier

### toSummaryString

public String toSummaryString()
Returns a superconcise version of the model

Specified by:
  `toSummaryString` in interface `Summarizable`
Returns:
  a summary of the model

### 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 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(String additionalMeasureName)
Returns the value of the named measure

Specified by:
  `getMeasure` in interface `AdditionalMeasureProducer`
Parameters:
  `additionalMeasureName` - the name of the measure to query for its value
Returns:
  the value of the named measure
Throws:
  `IllegalArgumentException` - if the named measure is not supported

### unprunedTipText

public String unprunedTipText()
Returns the tip text for this property

Returns:
  tip text for this property suitable for displaying in the explorer/experimenter gui

### getUnpruned

public boolean getUnpruned()
Get the value of unpruned.

Returns:
  Value of unpruned.

### setUnpruned

public void setUnpruned(boolean v)
Set the value of unpruned.

Parameters:
  `v` - Value to assign to unpruned.

### relabelTipText

public String relabelTipText()
Returns the tip text for this property

Returns:
  tip text for this property suitable for displaying in the explorer/experimenter gui

### getRelabel

public boolean getRelabel()
Get the value of relabelling

Returns:
  Value of relabelling.

### setRelabel

public void setRelabel(boolean v)
Set the value of relabelling.

Parameters:
  `v` - Value to assign to relabelling flag.

### confidenceFactorTipText

public String confidenceFactorTipText()
Returns the tip text for this property

Returns:
  tip text for this property suitable for displaying in the explorer/experimenter gui

### 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.

### minNumObjTipText

public String minNumObjTipText()
Returns the tip text for this property

Returns:
  tip text for this property suitable for displaying in the explorer/experimenter gui

### 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.

### binarySplitsTipText

public String binarySplitsTipText()
Returns the tip text for this property

Returns:
  tip text for this property suitable for displaying in the explorer/experimenter gui

### 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.

### subtreeRaisingTipText

public String subtreeRaisingTipText()
Returns the tip text for this property

Returns:
  tip text for this property suitable for displaying in the explorer/experimenter gui

### 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.

### saveInstanceDataTipText

public String saveInstanceDataTipText()
Returns the tip text for this property

Returns:
  tip text for this property suitable for displaying in the explorer/experimenter gui

### 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

### getRevision

public String getRevision()
Returns the revision string.

Specified by:
  `getRevision` in interface `RevisionHandler`
Overrides:
  `getRevision` in class `Classifier`
Returns:
  the revision

### main

public static void main(String[] argv)
Main method for testing this class

Parameters:
  `argv` - the commandline options