Package weka.classifiers.trees.m5
Class RuleNode
- java.lang.Object
-
- weka.classifiers.Classifier
-
- weka.classifiers.trees.m5.RuleNode
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable,CapabilitiesHandler,OptionHandler,RevisionHandler
public class RuleNode extends Classifier
Constructs a node for use in an m5 tree or rule- Version:
- $Revision: 1.13 $
- Author:
- Mark Hall (mhall@cs.waikato.ac.nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description intm_numParametersthe number of paramters in the chosen model for this node---either the subtree model or the linear model.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbuildClassifier(Instances data)Build this node (find an attribute and split point)doubleclassifyInstance(Instance inst)Classify an instance using this node.voidfindBestLeaf(double[] maxCoverage, RuleNode[] bestLeaf)Find the leaf with greatest coveragedoublegetMinNumInstances()Get the minimum number of instances to allow at a leaf nodePreConstructedLinearModelgetModel()Get the linear model at this nodeintgetNumInstances()Return the number of instances that reach this node.booleangetRegressionTree()Get the value of regressionTree.java.lang.StringgetRevision()Returns the revision string.voidgraph(java.lang.StringBuffer text)Assign a unique identifier to each node in the tree and then calls graphTreevoidinstallLinearModels()Traverses the tree and installs linear models at each node.voidinstallSmoothedModels()booleanisLeaf()Return true if this node is a leafRuleNodeleftNode()Get the left child of this nodejava.lang.StringnodeToString()Returns a description of this node (debugging purposes)intnumberOfLinearModels()Get the number of linear models in the treeintnumLeaves(int leafCounter)Sets the leaves' numbersRuleNodeparentNode()Get the parent of this nodevoidprintAllModels()Print all the linear models at the learf (debugging purposes)java.lang.StringprintLeafModels()print all leaf modelsjava.lang.StringprintNodeLinearModel()print the linear model at this nodevoidprune()Recursively prune the treevoidreturnLeaves(FastVector[] v)Return a list containing all the leaves in the treeRuleNoderightNode()Get the right child of this nodevoidsetMinNumInstances(double minNum)Set the minumum number of instances to allow at a leaf nodevoidsetRegressionTree(boolean newregressionTree)Set the value of regressionTree.voidsplit()Finds an attribute and split point for this nodeintsplitAtt()Get the index of the splitting attribute for this nodedoublesplitVal()Get the split point for this nodejava.lang.StringtoString()print the linear model at this nodejava.lang.StringtreeToString(int level)Recursively builds a textual description of the tree-
Methods inherited from class weka.classifiers.Classifier
debugTipText, distributionForInstance, forName, getCapabilities, getDebug, getOptions, listOptions, makeCopies, makeCopy, setDebug, setOptions
-
-
-
-
Constructor Detail
-
RuleNode
public RuleNode(double globalDev, double globalAbsDev, RuleNode parent)Creates a newRuleNodeinstance.- Parameters:
globalDev- the global standard deviation of the classglobalAbsDev- the global absolute deviation of the classparent- the parent of this node
-
-
Method Detail
-
buildClassifier
public void buildClassifier(Instances data) throws java.lang.Exception
Build this node (find an attribute and split point)- Specified by:
buildClassifierin classClassifier- Parameters:
data- the instances on which to build this node- Throws:
java.lang.Exception- if an error occurs
-
classifyInstance
public double classifyInstance(Instance inst) throws java.lang.Exception
Classify an instance using this node. Recursively calls classifyInstance on child nodes.- Overrides:
classifyInstancein classClassifier- Parameters:
inst- the instance to classify- Returns:
- the prediction for this instance
- Throws:
java.lang.Exception- if an error occurs
-
split
public void split() throws java.lang.ExceptionFinds an attribute and split point for this node- Throws:
java.lang.Exception- if an error occurs
-
numLeaves
public int numLeaves(int leafCounter)
Sets the leaves' numbers- Parameters:
leafCounter- the number of leaves counted- Returns:
- the number of the total leaves under the node
-
toString
public java.lang.String toString()
print the linear model at this node- Overrides:
toStringin classjava.lang.Object- Returns:
- the linear model
-
printNodeLinearModel
public java.lang.String printNodeLinearModel()
print the linear model at this node- Returns:
- the linear model at this node
-
printLeafModels
public java.lang.String printLeafModels()
print all leaf models- Returns:
- the leaf models
-
nodeToString
public java.lang.String nodeToString()
Returns a description of this node (debugging purposes)- Returns:
- a string describing this node
-
treeToString
public java.lang.String treeToString(int level)
Recursively builds a textual description of the tree- Parameters:
level- the level of this node- Returns:
- string describing the tree
-
installLinearModels
public void installLinearModels() throws java.lang.ExceptionTraverses the tree and installs linear models at each node. This method must be called if pruning is not to be performed.- Throws:
java.lang.Exception- if an error occurs
-
installSmoothedModels
public void installSmoothedModels() throws java.lang.Exception- Throws:
java.lang.Exception
-
prune
public void prune() throws java.lang.ExceptionRecursively prune the tree- Throws:
java.lang.Exception- if an error occurs
-
findBestLeaf
public void findBestLeaf(double[] maxCoverage, RuleNode[] bestLeaf)Find the leaf with greatest coverage- Parameters:
maxCoverage- the greatest coverage found so farbestLeaf- the leaf with the greatest coverage
-
returnLeaves
public void returnLeaves(FastVector[] v)
Return a list containing all the leaves in the tree- Parameters:
v- a single element array containing a vector of leaves
-
parentNode
public RuleNode parentNode()
Get the parent of this node- Returns:
- the parent of this node
-
leftNode
public RuleNode leftNode()
Get the left child of this node- Returns:
- the left child of this node
-
rightNode
public RuleNode rightNode()
Get the right child of this node- Returns:
- the right child of this node
-
splitAtt
public int splitAtt()
Get the index of the splitting attribute for this node- Returns:
- the index of the splitting attribute
-
splitVal
public double splitVal()
Get the split point for this node- Returns:
- the split point for this node
-
numberOfLinearModels
public int numberOfLinearModels()
Get the number of linear models in the tree- Returns:
- the number of linear models
-
isLeaf
public boolean isLeaf()
Return true if this node is a leaf- Returns:
- true if this node is a leaf
-
getModel
public PreConstructedLinearModel getModel()
Get the linear model at this node- Returns:
- the linear model at this node
-
getNumInstances
public int getNumInstances()
Return the number of instances that reach this node.- Returns:
- the number of instances at this node.
-
getRegressionTree
public boolean getRegressionTree()
Get the value of regressionTree.- Returns:
- Value of regressionTree.
-
setMinNumInstances
public void setMinNumInstances(double minNum)
Set the minumum number of instances to allow at a leaf node- Parameters:
minNum- the minimum number of instances
-
getMinNumInstances
public double getMinNumInstances()
Get the minimum number of instances to allow at a leaf node- Returns:
- a
doublevalue
-
setRegressionTree
public void setRegressionTree(boolean newregressionTree)
Set the value of regressionTree.- Parameters:
newregressionTree- Value to assign to regressionTree.
-
printAllModels
public void printAllModels()
Print all the linear models at the learf (debugging purposes)
-
graph
public void graph(java.lang.StringBuffer text)
Assign a unique identifier to each node in the tree and then calls graphTree- Parameters:
text- aStringBuffervalue
-
getRevision
public java.lang.String getRevision()
Returns the revision string.- Specified by:
getRevisionin interfaceRevisionHandler- Overrides:
getRevisionin classClassifier- Returns:
- the revision
-
-