Class ClassifierTree
- java.lang.Object
-
- org.processmining.plugins.workshop.Yaguang.WekaDiscriminationTree.ClassifierTree
-
- All Implemented Interfaces:
java.io.Serializable,Drawable
- Direct Known Subclasses:
C45PruneableClassifierTree,PruneableClassifierTree
public class ClassifierTree extends java.lang.Object implements Drawable, java.io.Serializable
Class for handling a tree structure used for classification.- Version:
- $Revision: 1.17.2.1 $
- Author:
- Eibe Frank (eibe@cs.waikato.ac.nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected intm_idThe id for the node.protected booleanm_isChangedindicate of the node is changed.protected booleanm_isDifferentprotected booleanm_isEmptyTrue if node is empty.protected booleanm_isLeafTrue if node is leaf.protected ClassifierSplitModelm_localModelLocal model at node.protected ClassifierTree[]m_sonsReferences to sons.protected Distributionm_testThe pruning instances.protected ModelSelectionm_toSelectModelThe model selection method.protected Instancesm_trainThe training instances.-
Fields inherited from interface org.processmining.plugins.workshop.Yaguang.WekaDiscriminationTree.Drawable
BayesNet, NOT_DRAWABLE, TREE
-
-
Constructor Summary
Constructors Constructor Description ClassifierTree(ModelSelection toSelectLocModel)Constructor.
-
Method Summary
All Methods Static 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.voidcolor(ClassifierTree m_root)Set m_isDifferent to true for those leafs of the classifireTree whose label are dofferent with the corresponding leaf in the input classifireTreedouble[]distributionForInstance(Instance instance, boolean useLaplace)Returns class probabilities for a weighted instance.voiddoChangeLeafLabels(java.util.Set<java.lang.Integer> nodeIdsToRelabel)double[][]doDistributionForInstance(Instance instance, boolean useLaplace)voiddoRelabel(java.util.Map<java.lang.Double,java.lang.Double[]> info, java.lang.Double[][] discriminationInfo, int NDCtoDC)java.util.Map<java.lang.Double,java.lang.Double[]>doRemoveUselessNodes(java.util.Map<java.lang.Double,java.lang.Double[]> info, java.lang.Double[][] discriminationInfo)java.lang.StringgetLabel()protected ClassifierTreegetNewTree(Instances data)Returns a newly created tree.protected ClassifierTreegetNewTree(Instances train, Instances test)Returns a newly created tree.java.lang.Stringgraph()Returns graph describing the tree.intgraphType()Returns the type of graph this classifier represents.booleanisLeaf()protected static longnextID()Gets the next unique node ID.intnumLeaves()Returns number of leaves in tree structure.intnumNodes()Returns number of nodes in tree structure.intpickMaxIdx(double[][] info)java.lang.Stringprefix()Returns tree in prefix order.protected static voidresetID()Resets the unique node ID counter (e.g.voidsetIsDifferent(boolean isDifferent)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.
-
-
-
Field Detail
-
m_toSelectModel
protected ModelSelection m_toSelectModel
The model selection method.
-
m_localModel
protected ClassifierSplitModel m_localModel
Local model at node.
-
m_sons
protected ClassifierTree[] m_sons
References to sons.
-
m_isLeaf
protected boolean m_isLeaf
True if node is leaf.
-
m_isEmpty
protected boolean m_isEmpty
True if node is empty.
-
m_isDifferent
protected boolean m_isDifferent
-
m_train
protected Instances m_train
The training instances.
-
m_test
protected Distribution m_test
The pruning instances.
-
m_id
protected int m_id
The id for the node.
-
m_isChanged
protected boolean m_isChanged
indicate of the node is changed.
-
-
Constructor Detail
-
ClassifierTree
public ClassifierTree(ModelSelection toSelectLocModel)
Constructor.
-
-
Method Detail
-
nextID
protected static long nextID()
Gets the next unique node ID.- Returns:
- the next unique node ID.
-
doRemoveUselessNodes
public java.util.Map<java.lang.Double,java.lang.Double[]> doRemoveUselessNodes(java.util.Map<java.lang.Double,java.lang.Double[]> info, java.lang.Double[][] discriminationInfo)
-
pickMaxIdx
public int pickMaxIdx(double[][] info)
-
doChangeLeafLabels
public void doChangeLeafLabels(java.util.Set<java.lang.Integer> nodeIdsToRelabel)
-
doRelabel
public void doRelabel(java.util.Map<java.lang.Double,java.lang.Double[]> info, java.lang.Double[][] discriminationInfo, int NDCtoDC)
-
resetID
protected static void resetID()
Resets the unique node ID counter (e.g. between repeated separate print types)
-
doDistributionForInstance
public final double[][] doDistributionForInstance(Instance instance, boolean useLaplace) throws java.lang.Exception
- Throws:
java.lang.Exception
-
buildClassifier
public void buildClassifier(Instances data) throws java.lang.Exception
Method for building a classifier tree.- 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.- Throws:
java.lang.Exception- if something goes wrong
-
cleanup
public final void cleanup(Instances justHeaderInfo)
Cleanup in order to save memory.
-
distributionForInstance
public final double[] distributionForInstance(Instance instance, boolean useLaplace) throws java.lang.Exception
Returns class probabilities for a weighted instance.- Throws:
java.lang.Exception- if something goes wrong
-
assignIDs
public int assignIDs(int lastID)
Assigns a uniqe id to every node in the tree.
-
isLeaf
public boolean isLeaf()
-
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.- Throws:
java.lang.Exception- if something goes wrong
-
getLabel
public java.lang.String getLabel() throws java.lang.Exception- Throws:
java.lang.Exception
-
setIsDifferent
public void setIsDifferent(boolean isDifferent)
-
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.
-
numNodes
public int numNodes()
Returns number of nodes in tree structure.
-
toString
public java.lang.String toString()
Prints tree structure.- Overrides:
toStringin classjava.lang.Object
-
getNewTree
protected ClassifierTree getNewTree(Instances data) throws java.lang.Exception
Returns a newly created tree.- Parameters:
data- the training data- Throws:
java.lang.Exception- if something goes wrong
-
getNewTree
protected ClassifierTree getNewTree(Instances train, Instances test) throws java.lang.Exception
Returns a newly created tree.- Parameters:
data- the training datatest- the pruning data.- Throws:
java.lang.Exception- if something goes wrong
-
color
public void color(ClassifierTree m_root) throws java.lang.Exception
Set m_isDifferent to true for those leafs of the classifireTree whose label are dofferent with the corresponding leaf in the input classifireTree- Throws:
java.lang.Exception
-
-