weka.classifiers.trees.m5
Class Rule

java.lang.Object
  extended byweka.classifiers.trees.m5.Rule
All Implemented Interfaces:
java.io.Serializable

public class Rule
extends java.lang.Object
implements java.io.Serializable

Generates a single m5 tree or rule

Version:
$Revision: 1.10 $
Author:
Mark Hall
See Also:
Serialized Form

Field Summary
protected static int LEFT
           
private  int m_classIndex
          the class index
private  Instances m_covered
          the instances covered by this rule
private  double m_globalAbsDev
          the absolute deviation of the class for all the instances
private  double m_globalStdDev
          the standard deviation of the class for all the instances
private  Instances m_instances
          the instances covered by this rule
private  RuleNode[] m_internalNodes
          the corresponding internal nodes.
private  double m_minNumInstances
          The minimum number of instances to allow at a leaf node
private  Instances m_notCovered
          the instances not covered by this rule
private  int m_numAttributes
          the number of attributes
private  int m_numCovered
          the number of instances covered by this rule
private  int m_numInstances
          the number of instances in the dataset
private  boolean m_regressionTree
          Make a regression tree instead of a model tree
private  int[] m_relOps
          the corresponding relational operators (0 = "<=", 1 = ">")
private  RuleNode m_ruleModel
          the leaf encapsulating the linear model for this rule
private  boolean m_saveInstances
          Save instances at each node in an M5 tree for visualization purposes.
private  boolean m_smoothPredictions
          use the original m5 smoothing procedure
private  int[] m_splitAtts
          the indexes of the attributes used to split on for this rule
private  double[] m_splitVals
          the corresponding values of the split points
protected  RuleNode m_topOfTree
          the top of the m5 tree for this rule
private  boolean m_useTree
          use a pruned m5 tree rather than make a rule
private  boolean m_useUnpruned
          Build unpruned tree/rule
protected static int RIGHT
           
 
Constructor Summary
Rule()
          Constructor declaration
 
Method Summary
protected static double absDev(int attr, Instances inst)
          Returns the absolute deviation value of the supplied attribute index.
 void buildClassifier(Instances data)
          Generates a single rule or m5 model tree.
 double classifyInstance(Instance instance)
          Calculates a prediction for an instance using this rule or M5 model tree
 RuleNode getM5RootNode()
           
 double getMinNumInstances()
          Get the minimum number of instances to allow at a leaf node
 boolean getRegressionTree()
          Get the value of regressionTree.
 boolean getSmoothing()
          Get whether or not smoothing has been turned on
 boolean getUnpruned()
          Get whether unpruned tree/rules are being generated
 boolean getUseTree()
          get whether an m5 tree is being used rather than rules
private  void makeRule()
          Make the single best rule from a pruned m5 model tree
 Instances notCoveredInstances()
          Get the instances not covered by this rule
private  java.lang.String ruleToString()
          Return a description of the rule
 void setMinNumInstances(double minNum)
          Set the minumum number of instances to allow at a leaf node
 void setRegressionTree(boolean newregressionTree)
          Set the value of regressionTree.
protected  void setSaveInstances(boolean save)
          Sets whether instances at each node in an M5 tree should be saved for visualization purposes.
 void setSmoothing(boolean s)
          Smooth predictions
 void setUnpruned(boolean unpruned)
          Use unpruned tree/rules
 void setUseTree(boolean u)
          Use an m5 tree rather than generate rules
protected static double stdDev(int attr, Instances inst)
          Returns the standard deviation value of the supplied attribute index.
 RuleNode topOfTree()
          Returns the top of the tree.
 java.lang.String toString()
          Return a description of the m5 tree or rule
private  java.lang.String treeToString()
          Return a description of the m5 tree
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

LEFT

protected static int LEFT

RIGHT

protected static int RIGHT

m_instances

private Instances m_instances
the instances covered by this rule


m_classIndex

private int m_classIndex
the class index


m_numAttributes

private int m_numAttributes
the number of attributes


m_numInstances

private int m_numInstances
the number of instances in the dataset


m_splitAtts

private int[] m_splitAtts
the indexes of the attributes used to split on for this rule


m_splitVals

private double[] m_splitVals
the corresponding values of the split points


m_internalNodes

private RuleNode[] m_internalNodes
the corresponding internal nodes. Used for smoothing rules.


m_relOps

private int[] m_relOps
the corresponding relational operators (0 = "<=", 1 = ">")


m_ruleModel

private RuleNode m_ruleModel
the leaf encapsulating the linear model for this rule


m_topOfTree

protected RuleNode m_topOfTree
the top of the m5 tree for this rule


m_globalStdDev

private double m_globalStdDev
the standard deviation of the class for all the instances


m_globalAbsDev

private double m_globalAbsDev
the absolute deviation of the class for all the instances


m_covered

private Instances m_covered
the instances covered by this rule


m_numCovered

private int m_numCovered
the number of instances covered by this rule


m_notCovered

private Instances m_notCovered
the instances not covered by this rule


m_useTree

private boolean m_useTree
use a pruned m5 tree rather than make a rule


m_smoothPredictions

private boolean m_smoothPredictions
use the original m5 smoothing procedure


m_saveInstances

private boolean m_saveInstances
Save instances at each node in an M5 tree for visualization purposes.


m_regressionTree

private boolean m_regressionTree
Make a regression tree instead of a model tree


m_useUnpruned

private boolean m_useUnpruned
Build unpruned tree/rule


m_minNumInstances

private double m_minNumInstances
The minimum number of instances to allow at a leaf node

Constructor Detail

Rule

public Rule()
Constructor declaration

Method Detail

buildClassifier

public void buildClassifier(Instances data)
                     throws java.lang.Exception
Generates a single rule or m5 model tree.

Parameters:
data - set of instances serving as training data
Throws:
java.lang.Exception - if the rule has not been generated successfully

classifyInstance

public double classifyInstance(Instance instance)
                        throws java.lang.Exception
Calculates a prediction for an instance using this rule or M5 model tree

Returns:
the prediction
Throws:
if - a prediction can't be made.
java.lang.Exception

topOfTree

public RuleNode topOfTree()
Returns the top of the tree.


makeRule

private void makeRule()
               throws java.lang.Exception
Make the single best rule from a pruned m5 model tree

Throws:
if - something goes wrong.
java.lang.Exception

toString

public java.lang.String toString()
Return a description of the m5 tree or rule

Returns:
a description of the m5 tree or rule as a String

treeToString

private java.lang.String treeToString()
Return a description of the m5 tree

Returns:
a description of the m5 tree as a String

ruleToString

private java.lang.String ruleToString()
Return a description of the rule

Returns:
a description of the rule as a String

setUnpruned

public void setUnpruned(boolean unpruned)
Use unpruned tree/rules

Parameters:
unpruned - true if unpruned tree/rules are to be generated

getUnpruned

public boolean getUnpruned()
Get whether unpruned tree/rules are being generated

Returns:
true if unpruned tree/rules are to be generated

setUseTree

public void setUseTree(boolean u)
Use an m5 tree rather than generate rules

Parameters:
u - true if m5 tree is to be used

getUseTree

public boolean getUseTree()
get whether an m5 tree is being used rather than rules

Returns:
true if an m5 tree is being used.

setSmoothing

public void setSmoothing(boolean s)
Smooth predictions

Parameters:
s - true if smoothing is to be used

getSmoothing

public boolean getSmoothing()
Get whether or not smoothing has been turned on

Returns:
true if smoothing is being used

notCoveredInstances

public Instances notCoveredInstances()
Get the instances not covered by this rule

Returns:
the instances not covered

stdDev

protected static final double stdDev(int attr,
                                     Instances inst)
Returns the standard deviation value of the supplied attribute index.

Parameters:
attr - an attribute index
inst - the instances
Returns:
the standard deviation value

absDev

protected static final double absDev(int attr,
                                     Instances inst)
Returns the absolute deviation value of the supplied attribute index.

Parameters:
attr - an attribute index
inst - the instances
Returns:
the absolute deviation value

setSaveInstances

protected void setSaveInstances(boolean save)
Sets whether instances at each node in an M5 tree should be saved for visualization purposes. Default is to save memory.

Parameters:
save - a boolean value

getRegressionTree

public boolean getRegressionTree()
Get the value of regressionTree.

Returns:
Value of regressionTree.

setRegressionTree

public void setRegressionTree(boolean newregressionTree)
Set the value of regressionTree.

Parameters:
newregressionTree - Value to assign to 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 double value

getM5RootNode

public RuleNode getM5RootNode()