Package weka.classifiers.trees.m5
Class RuleNode2
- java.lang.Object
-
- weka.classifiers.AbstractClassifier
-
- weka.classifiers.trees.m5.RuleNode2
-
- All Implemented Interfaces:
Serializable,Cloneable,weka.classifiers.Classifier,weka.core.BatchPredictor,weka.core.CapabilitiesHandler,weka.core.CapabilitiesIgnorer,weka.core.CommandlineRunnable,weka.core.OptionHandler,weka.core.RevisionHandler
public class RuleNode2 extends weka.classifiers.AbstractClassifierConstructs a node for use in an m5 tree or rule- Version:
- $Revision$
- Author:
- Mark Hall ([email protected])
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected RuleNode2m_leftleft child nodeprotected intm_numInstancesthe number of instances reaching this nodeintm_numParametersthe number of paramters in the chosen model for this node---either the subtree model or the linear model.protected RuleNode2m_rightright child node
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected intassignIDs(int lastID)Assigns a unique identifier to each node in the treevoidbuildClassifier(weka.core.Instances data)Build this node (find an attribute and split point)doubleclassifyInstance(weka.core.Instance inst)Classify an instance using this node.voidfindBestLeaf(double[] maxCoverage, RuleNode2[] bestLeaf)Find the leaf with greatest coveragedoublegetMinNumInstances()Get the minimum number of instances to allow at a leaf nodeweka.classifiers.trees.m5.PreConstructedLinearModelgetModel()Get the linear model at this nodeintgetNumInstances()Return the number of instances that reach this node.booleangetRegressionTree()Get the value of regressionTree.StringgetRevision()Returns the revision string.voidgraph(StringBuffer text)Assign a unique identifier to each node in the tree and then calls graphTreeprotected voidgraphTree(StringBuffer text)Return a dotty style string describing the treevoidinstallLinearModels()Traverses the tree and installs linear models at each node.voidinstallSmoothedModels()booleanisLeaf()Return true if this node is a leafRuleNode2leftNode()Get the left child of this nodeStringnodeToString()Returns a description of this node (debugging purposes)intnumberOfLinearModels()Get the number of linear models in the treeintnumLeaves(int leafCounter)Sets the leaves' numbersRuleNode2parentNode()Get the parent of this nodevoidprintAllModels()Print all the linear models at the learf (debugging purposes)StringprintLeafModels()print all leaf modelsStringprintNodeLinearModel()print the linear model at this nodevoidprune()Recursively prune the treevoidreturnLeaves(weka.core.FastVector[] v)Return a list containing all the leaves in the treeRuleNode2rightNode()Get the right child of this nodeprotected doublerootMeanSquaredError()Get the root mean squared error at this nodevoidsetMinNumInstances(double minNum)Set the minumum number of instances to allow at a leaf nodevoidsetRegressionTree(boolean newregressionTree)Set the value of regressionTree.protected voidsetSaveInstances(boolean save)Set whether to save instances for visualization purposes.protected static doublesmoothingOriginal(double n, double pred, double supportPred)Applies the m5 smoothing procedure to a predictionvoidsplit()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 nodeStringtoString()print the linear model at this nodeStringtreeToString(int level)Recursively builds a textual description of the tree-
Methods inherited from class weka.classifiers.AbstractClassifier
batchSizeTipText, debugTipText, distributionForInstance, distributionsForInstances, doNotCheckCapabilitiesTipText, forName, getBatchSize, getCapabilities, getDebug, getDoNotCheckCapabilities, getNumDecimalPlaces, getOptions, implementsMoreEfficientBatchPrediction, listOptions, makeCopies, makeCopy, numDecimalPlacesTipText, postExecution, preExecution, run, runClassifier, setBatchSize, setDebug, setDoNotCheckCapabilities, setNumDecimalPlaces, setOptions
-
-
-
-
Field Detail
-
m_numInstances
protected int m_numInstances
the number of instances reaching this node
-
m_numParameters
public int m_numParameters
the number of paramters in the chosen model for this node---either the subtree model or the linear model. The constant term is counted as a paramter---this is for pruning purposes
-
m_left
protected RuleNode2 m_left
left child node
-
m_right
protected RuleNode2 m_right
right child node
-
-
Constructor Detail
-
RuleNode2
public RuleNode2(double globalDev, double globalAbsDev, RuleNode2 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(weka.core.Instances data) throws ExceptionBuild this node (find an attribute and split point)- Parameters:
data- the instances on which to build this node- Throws:
Exception- if an error occurs
-
classifyInstance
public double classifyInstance(weka.core.Instance inst) throws ExceptionClassify an instance using this node. Recursively calls classifyInstance on child nodes.- Specified by:
classifyInstancein interfaceweka.classifiers.Classifier- Overrides:
classifyInstancein classweka.classifiers.AbstractClassifier- Parameters:
inst- the instance to classify- Returns:
- the prediction for this instance
- Throws:
Exception- if an error occurs
-
smoothingOriginal
protected static double smoothingOriginal(double n, double pred, double supportPred) throws ExceptionApplies the m5 smoothing procedure to a prediction- Parameters:
n- number of instances in selected child of this nodepred- the prediction so farsupportPred- the prediction of the linear model at this node- Returns:
- the current prediction smoothed with the prediction of the linear model at this node
- Throws:
Exception- if an error occurs
-
split
public void split() throws ExceptionFinds an attribute and split point for this node- Throws:
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 String toString()
print the linear model at this node
-
printNodeLinearModel
public String printNodeLinearModel()
print the linear model at this node- Returns:
- the linear model at this node
-
printLeafModels
public String printLeafModels()
print all leaf models- Returns:
- the leaf models
-
nodeToString
public String nodeToString()
Returns a description of this node (debugging purposes)- Returns:
- a string describing this node
-
treeToString
public 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 ExceptionTraverses the tree and installs linear models at each node. This method must be called if pruning is not to be performed.- Throws:
Exception- if an error occurs
-
prune
public void prune() throws ExceptionRecursively prune the tree- Throws:
Exception- if an error occurs
-
findBestLeaf
public void findBestLeaf(double[] maxCoverage, RuleNode2[] 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(weka.core.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 RuleNode2 parentNode()
Get the parent of this node- Returns:
- the parent of this node
-
leftNode
public RuleNode2 leftNode()
Get the left child of this node- Returns:
- the left child of this node
-
rightNode
public RuleNode2 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
-
rootMeanSquaredError
protected double rootMeanSquaredError()
Get the root mean squared error at this node- Returns:
- the root mean squared error
-
getModel
public weka.classifiers.trees.m5.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)
-
assignIDs
protected int assignIDs(int lastID)
Assigns a unique identifier to each node in the tree- Parameters:
lastID- last id number used- Returns:
- ID after processing child nodes
-
graph
public void graph(StringBuffer text)
Assign a unique identifier to each node in the tree and then calls graphTree- Parameters:
text- aStringBuffervalue
-
graphTree
protected void graphTree(StringBuffer text)
Return a dotty style string describing the tree- Parameters:
text- aStringBuffervalue
-
setSaveInstances
protected void setSaveInstances(boolean save)
Set whether to save instances for visualization purposes. Default is to save memory.- Parameters:
save- abooleanvalue
-
getRevision
public String getRevision()
Returns the revision string.- Specified by:
getRevisionin interfaceweka.core.RevisionHandler- Overrides:
getRevisionin classweka.classifiers.AbstractClassifier- Returns:
- the revision
-
-