Package weka.classifiers.trees.j48
Class ClassifierTree
- java.lang.Object
-
- weka.classifiers.trees.j48.ClassifierTree
-
- All Implemented Interfaces:
java.io.Serializable,CapabilitiesHandler,Drawable,RevisionHandler
- Direct Known Subclasses:
C45PruneableClassifierTree,NBTreeClassifierTree,PruneableClassifierTree
public class ClassifierTree extends java.lang.Object implements Drawable, java.io.Serializable, RevisionHandler, CapabilitiesHandler
Class for handling a tree structure used for classification.- Version:
- $Revision: 15123 $
- Author:
- Eibe Frank (eibe@cs.waikato.ac.nz)
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from interface weka.core.Drawable
BayesNet, Newick, NOT_DRAWABLE, TREE
-
-
Constructor Summary
Constructors Constructor Description ClassifierTree(ModelSelection toSelectLocModel)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intassignIDs(int lastID)Assigns a uniqe id to every node in the tree.voidbuildClassifier(Instances data)Method for building a classifier tree.voidbuildTree(Instances data, boolean keepData)Builds the tree structure.voidbuildTree(Instances train, Instances test, boolean keepData)Builds the tree structure with hold out setdoubleclassifyInstance(Instance instance)Classifies an instance.voidcleanup(Instances justHeaderInfo)Cleanup in order to save memory.double[]distributionForInstance(Instance instance, boolean useLaplace)Returns class probabilities for a weighted instance.CapabilitiesgetCapabilities()Returns default capabilities of the classifier tree.ClassifierSplitModelgetLocalModel()double[]getMembershipValues(Instance instance)Computes a list that indicates node membershipjava.lang.StringgetRevision()Returns the revision string.ClassifierTree[]getSons()InstancesgetTrainingData()java.lang.Stringgraph()Returns graph describing the tree.intgraphType()Returns the type of graph this classifier represents.booleanisLeaf()intnumLeaves()Returns number of leaves in tree structure.intnumNodes()Returns number of nodes in tree structure.java.lang.Stringprefix()Returns tree in prefix order.java.lang.StringBuffer[]toSource(java.lang.String className)Returns source code for the tree as an if-then statement.java.lang.StringtoString()Prints tree structure.
-
-
-
Constructor Detail
-
ClassifierTree
public ClassifierTree(ModelSelection toSelectLocModel)
Constructor.
-
-
Method Detail
-
getLocalModel
public ClassifierSplitModel getLocalModel()
-
getSons
public ClassifierTree[] getSons()
-
isLeaf
public boolean isLeaf()
-
getTrainingData
public Instances getTrainingData()
-
getCapabilities
public Capabilities getCapabilities()
Returns default capabilities of the classifier tree.- Specified by:
getCapabilitiesin interfaceCapabilitiesHandler- Returns:
- the capabilities of this classifier tree
- See Also:
Capabilities
-
buildClassifier
public void buildClassifier(Instances data) throws java.lang.Exception
Method for building a classifier tree.- Parameters:
data- the data to build the tree from- Throws:
java.lang.Exception- if something goes wrong
-
buildTree
public void buildTree(Instances data, boolean keepData) throws java.lang.Exception
Builds the tree structure.- Parameters:
data- the data for which the tree structure is to be generated.keepData- is training data to be kept?- Throws:
java.lang.Exception- if something goes wrong
-
buildTree
public void buildTree(Instances train, Instances test, boolean keepData) throws java.lang.Exception
Builds the tree structure with hold out set- Parameters:
train- the data for which the tree structure is to be generated.test- the test data for potential pruningkeepData- is training Data to be kept?- Throws:
java.lang.Exception- if something goes wrong
-
classifyInstance
public double classifyInstance(Instance instance) throws java.lang.Exception
Classifies an instance.- Parameters:
instance- the instance to classify- Returns:
- the classification
- Throws:
java.lang.Exception- if something goes wrong
-
cleanup
public final void cleanup(Instances justHeaderInfo)
Cleanup in order to save memory.- Parameters:
justHeaderInfo-
-
distributionForInstance
public double[] distributionForInstance(Instance instance, boolean useLaplace) throws java.lang.Exception
Returns class probabilities for a weighted instance.- Parameters:
instance- the instance to get the distribution foruseLaplace- whether to use laplace or not- Returns:
- the distribution
- Throws:
java.lang.Exception- if something goes wrong
-
assignIDs
public int assignIDs(int lastID)
Assigns a uniqe id to every node in the tree.- Parameters:
lastID- the last ID that was assign- Returns:
- the new current ID
-
graphType
public int graphType()
Returns the type of graph this classifier represents.
-
graph
public java.lang.String graph() throws java.lang.ExceptionReturns graph describing the tree.
-
prefix
public java.lang.String prefix() throws java.lang.ExceptionReturns tree in prefix order.- Returns:
- the prefix order
- Throws:
java.lang.Exception- if something goes wrong
-
toSource
public java.lang.StringBuffer[] toSource(java.lang.String className) throws java.lang.ExceptionReturns source code for the tree as an if-then statement. The class is assigned to variable "p", and assumes the tested instance is named "i". The results are returned as two stringbuffers: a section of code for assignment of the class, and a section of code containing support code (eg: other support methods).- Parameters:
className- the classname that this static classifier has- Returns:
- an array containing two stringbuffers, the first string containing assignment code, and the second containing source for support code.
- Throws:
java.lang.Exception- if something goes wrong
-
numLeaves
public int numLeaves()
Returns number of leaves in tree structure.- Returns:
- the number of leaves
-
numNodes
public int numNodes()
Returns number of nodes in tree structure.- Returns:
- the number of nodes
-
toString
public java.lang.String toString()
Prints tree structure.- Overrides:
toStringin classjava.lang.Object- Returns:
- the tree structure
-
getMembershipValues
public double[] getMembershipValues(Instance instance) throws java.lang.Exception
Computes a list that indicates node membership- Throws:
java.lang.Exception
-
getRevision
public java.lang.String getRevision()
Returns the revision string.- Specified by:
getRevisionin interfaceRevisionHandler- Returns:
- the revision
-
-