Package weka.classifiers.trees
Class J48
java.lang.Object
weka.classifiers.AbstractClassifier
weka.classifiers.trees.J48
- All Implemented Interfaces:
Serializable
,Cloneable
,Classifier
,Sourcable
,AdditionalMeasureProducer
,BatchPredictor
,CapabilitiesHandler
,CapabilitiesIgnorer
,CommandlineRunnable
,Drawable
,Matchable
,OptionHandler
,PartitionGenerator
,RevisionHandler
,Summarizable
,TechnicalInformationHandler
,WeightedInstancesHandler
public class J48
extends AbstractClassifier
implements OptionHandler, Drawable, Matchable, Sourcable, WeightedInstancesHandler, Summarizable, AdditionalMeasureProducer, TechnicalInformationHandler, PartitionGenerator
Class for generating a pruned or unpruned C4.5
decision tree. For more information, see
Ross Quinlan (1993). C4.5: Programs for Machine Learning. Morgan Kaufmann Publishers, San Mateo, CA. BibTeX:
Ross Quinlan (1993). C4.5: Programs for Machine Learning. Morgan Kaufmann Publishers, San Mateo, CA. BibTeX:
@book{Quinlan1993, address = {San Mateo, CA}, author = {Ross Quinlan}, publisher = {Morgan Kaufmann Publishers}, title = {C4.5: Programs for Machine Learning}, year = {1993} }Valid options are:
-U Use unpruned tree.
-O Do not collapse 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)
-R Use reduced error pruning.
-N <number of folds> Set number of folds for reduced error pruning. One fold is used as pruning set. (default 3)
-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.
-J Do not use MDL correction for info gain on numeric attributes.
-Q <seed> Seed for random data shuffling (default 1).
-doNotMakeSplitPointActualValue Do not make split point actual value.
- Version:
- $Revision: 15519 $
- Author:
- Eibe Frank (eibe@cs.waikato.ac.nz)
- See Also:
-
Field Summary
Fields inherited from class weka.classifiers.AbstractClassifier
BATCH_SIZE_DEFAULT, NUM_DECIMAL_PLACES_DEFAULT
Fields inherited from interface weka.core.Drawable
BayesNet, Newick, NOT_DRAWABLE, TREE
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionReturns the tip text for this propertyvoid
buildClassifier
(Instances instances) Generates the classifier.double
classifyInstance
(Instance instance) Classifies an instance.Returns the tip text for this propertyReturns the tip text for this propertyfinal double[]
distributionForInstance
(Instance instance) Returns class probabilities for an instance.Returns the tip text for this propertyReturns an enumeration of the additional measure namesvoid
generatePartition
(Instances data) Builds the classifier to generate a partition.boolean
Get the value of binarySplits.Returns default capabilities of the classifier.boolean
Get the value of collapseTree.float
Get the value of CF.boolean
Gets the value of doNotMakeSplitPointActualValue.double
getMeasure
(String additionalMeasureName) Returns the value of the named measuredouble[]
getMembershipValues
(Instance inst) Computes an array that indicates node membership.int
Get the value of minNumObj.int
Get the value of numFolds.String[]
Gets the current settings of the Classifier.boolean
Get the value of reducedErrorPruning.Returns the revision string.boolean
Check whether instance data is to be saved.int
getSeed()
Get the value of Seed.boolean
Get the value of subtreeRaising.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
Get the value of unpruned.boolean
Get the value of useLaplace.boolean
Get the value of useMDLcorrection.Returns a string describing classifiergraph()
Returns graph describing the tree.int
Returns the type of graph this classifier represents.Returns an enumeration describing the available options.static void
Main method for testing this classdouble
Returns the number of leavesdouble
Returns the number of rules (same as number of leaves)double
Returns the size of the treeReturns the tip text for this propertyint
Returns the number of elements in the partition.Returns the tip text for this propertyprefix()
Returns tree in prefix order.Returns the tip text for this propertyReturns the tip text for this propertyReturns the tip text for this propertyvoid
setBinarySplits
(boolean v) Set the value of binarySplits.void
setCollapseTree
(boolean v) Set the value of collapseTree.void
setConfidenceFactor
(float v) Set the value of CF.void
setDoNotMakeSplitPointActualValue
(boolean m_doNotMakeSplitPointActualValue) Sets the value of doNotMakeSplitPointActualValue.void
setMinNumObj
(int v) Set the value of minNumObj.void
setNumFolds
(int v) Set the value of numFolds.void
setOptions
(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
setSeed
(int newSeed) Set the value of Seed.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.void
setUseMDLcorrection
(boolean newuseMDLcorrection) Set the value of useMDLcorrection.Returns the tip text for this propertyReturns tree as an if-then statement.toString()
Returns a description of the classifier.Returns a superconcise version of the modelReturns the tip text for this propertyReturns the tip text for this propertyReturns the tip text for this propertyMethods inherited from class weka.classifiers.AbstractClassifier
batchSizeTipText, debugTipText, distributionsForInstances, doNotCheckCapabilitiesTipText, forName, getBatchSize, getDebug, getDoNotCheckCapabilities, getNumDecimalPlaces, implementsMoreEfficientBatchPrediction, makeCopies, makeCopy, numDecimalPlacesTipText, postExecution, preExecution, run, runClassifier, setBatchSize, setDebug, setDoNotCheckCapabilities, setNumDecimalPlaces
-
Constructor Details
-
J48
public J48()
-
-
Method Details
-
globalInfo
Returns a string describing classifier- Returns:
- a description suitable for displaying in the explorer/experimenter gui
-
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 interfaceTechnicalInformationHandler
- Returns:
- the technical information about this class
-
getCapabilities
Returns default capabilities of the classifier.- Specified by:
getCapabilities
in interfaceCapabilitiesHandler
- Specified by:
getCapabilities
in interfaceClassifier
- Overrides:
getCapabilities
in classAbstractClassifier
- Returns:
- the capabilities of this classifier
- See Also:
-
buildClassifier
Generates the classifier.- Specified by:
buildClassifier
in interfaceClassifier
- Parameters:
instances
- the data to train the classifier with- Throws:
Exception
- if classifier can't be built successfully
-
classifyInstance
Classifies an instance.- Specified by:
classifyInstance
in interfaceClassifier
- Overrides:
classifyInstance
in classAbstractClassifier
- Parameters:
instance
- the instance to classify- Returns:
- the classification for the instance
- Throws:
Exception
- if instance can't be classified successfully
-
distributionForInstance
Returns class probabilities for an instance.- Specified by:
distributionForInstance
in interfaceClassifier
- Overrides:
distributionForInstance
in classAbstractClassifier
- 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. -
graph
Returns graph describing the tree. -
prefix
Returns tree in prefix order. -
toSource
Returns tree as an if-then statement. -
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.-Q
The seed for reduced-error pruning.- Specified by:
listOptions
in interfaceOptionHandler
- Overrides:
listOptions
in classAbstractClassifier
- Returns:
- an enumeration of all the available options.
-
setOptions
Parses a given list of options. Valid options are:-U Use unpruned tree.
-O Do not collapse 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)
-R Use reduced error pruning.
-N <number of folds> Set number of folds for reduced error pruning. One fold is used as pruning set. (default 3)
-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.
-J Do not use MDL correction for info gain on numeric attributes.
-Q <seed> Seed for random data shuffling (default 1).
-doNotMakeSplitPointActualValue Do not make split point actual value.
- Specified by:
setOptions
in interfaceOptionHandler
- Overrides:
setOptions
in classAbstractClassifier
- Parameters:
options
- the list of options as an array of strings- Throws:
Exception
- if an option is not supported
-
getOptions
Gets the current settings of the Classifier.- Specified by:
getOptions
in interfaceOptionHandler
- Overrides:
getOptions
in classAbstractClassifier
- Returns:
- an array of strings suitable for passing to setOptions
-
seedTipText
Returns the tip text for this property- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
getSeed
public int getSeed()Get the value of Seed.- Returns:
- Value of Seed.
-
setSeed
public void setSeed(int newSeed) Set the value of Seed.- Parameters:
newSeed
- Value to assign to Seed.
-
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.
-
useMDLcorrectionTipText
Returns the tip text for this property- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
getUseMDLcorrection
public boolean getUseMDLcorrection()Get the value of useMDLcorrection.- Returns:
- Value of useMDLcorrection.
-
setUseMDLcorrection
public void setUseMDLcorrection(boolean newuseMDLcorrection) Set the value of useMDLcorrection.- Parameters:
newuseMDLcorrection
- Value to assign to useMDLcorrection.
-
toString
Returns a description of the classifier. -
toSummaryString
Returns a superconcise version of the model- Specified by:
toSummaryString
in interfaceSummarizable
- 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
Returns an enumeration of the additional measure names- Specified by:
enumerateMeasures
in interfaceAdditionalMeasureProducer
- Returns:
- an enumeration of the measure names
-
getMeasure
Returns the value of the named measure- Specified by:
getMeasure
in interfaceAdditionalMeasureProducer
- 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
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. Turns reduced-error pruning off if set.- Parameters:
v
- Value to assign to unpruned.
-
collapseTreeTipText
Returns the tip text for this property- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
getCollapseTree
public boolean getCollapseTree()Get the value of collapseTree.- Returns:
- Value of collapseTree.
-
setCollapseTree
public void setCollapseTree(boolean v) Set the value of collapseTree.- Parameters:
v
- Value to assign to collapseTree.
-
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
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.
-
reducedErrorPruningTipText
Returns the tip text for this property- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
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.
-
numFoldsTipText
Returns the tip text for this property- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
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.
-
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
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
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
-
doNotMakeSplitPointActualValueTipText
Returns the tip text for this property- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
getDoNotMakeSplitPointActualValue
public boolean getDoNotMakeSplitPointActualValue()Gets the value of doNotMakeSplitPointActualValue.- Returns:
- the value
-
setDoNotMakeSplitPointActualValue
public void setDoNotMakeSplitPointActualValue(boolean m_doNotMakeSplitPointActualValue) Sets the value of doNotMakeSplitPointActualValue.- Parameters:
m_doNotMakeSplitPointActualValue
- the value to set
-
getRevision
Returns the revision string.- Specified by:
getRevision
in interfaceRevisionHandler
- Overrides:
getRevision
in classAbstractClassifier
- Returns:
- the revision
-
generatePartition
Builds the classifier to generate a partition.- Specified by:
generatePartition
in interfacePartitionGenerator
- Throws:
Exception
-
getMembershipValues
Computes an array that indicates node membership.- Specified by:
getMembershipValues
in interfacePartitionGenerator
- Throws:
Exception
-
numElements
Returns the number of elements in the partition.- Specified by:
numElements
in interfacePartitionGenerator
- Throws:
Exception
-
main
Main method for testing this class- Parameters:
argv
- the commandline options
-