weka.classifiers.trees.m5
Class M5Base

java.lang.Object
  extended byweka.classifiers.Classifier
      extended byweka.classifiers.trees.m5.M5Base
All Implemented Interfaces:
AdditionalMeasureProducer, java.lang.Cloneable, OptionHandler, java.io.Serializable
Direct Known Subclasses:
M5P, M5Rules

public abstract class M5Base
extends Classifier
implements OptionHandler, AdditionalMeasureProducer

M5Base. Implements base routines for generating M5 Model trees and rules.

Valid options are:

-U
Use unsmoothed predictions.

-R
Build regression tree/rule rather than model tree/rule

Version:
$Revision: 1.9 $
See Also:
Serialized Form

Field Summary
private  int m_classIndex
          the class index
private  boolean m_generateRules
          generate a decision list instead of a single tree.
private  Instances m_instances
          the instances covered by the tree/rules
protected  double m_minNumInstances
          The minimum number of instances to allow at a leaf node
private  NominalToBinary m_nominalToBinary
          filter to convert nominal attributes to binary
private  int m_numAttributes
          the number of attributes
private  int m_numInstances
          the number of instances in the dataset
protected  boolean m_regressionTree
          Make a regression tree/rule instead of a model tree/rule
private  ReplaceMissingValues m_replaceMissing
          filter to fill in missing values
protected  FastVector m_ruleSet
          the rule set
protected  boolean m_saveInstances
          Save instances at each node in an M5 tree for visualization purposes.
private  boolean m_unsmoothedPredictions
          use unsmoothed predictions
protected  boolean m_useUnpruned
          Do not prune tree/rules
 
Fields inherited from class weka.classifiers.Classifier
m_Debug
 
Constructor Summary
M5Base()
          Constructor
 
Method Summary
 void buildClassifier(Instances data)
          Generates the classifier.
 double classifyInstance(Instance inst)
          Calculates a prediction for an instance using a set of rules or an M5 model tree
 java.util.Enumeration enumerateMeasures()
          Returns an enumeration of the additional measure names
 boolean getBuildRegressionTree()
          Get the value of regressionTree.
protected  boolean getGenerateRules()
          get whether rules are being generated rather than a tree
 RuleNode getM5RootNode()
           
 double getMeasure(java.lang.String additionalMeasureName)
          Returns the value of the named measure
 double getMinNumInstances()
          Get the minimum number of instances to allow at a leaf node
 java.lang.String[] getOptions()
          Gets the current settings of the classifier.
 boolean getUnpruned()
          Get whether unpruned tree/rules are being generated
 boolean getUseUnsmoothed()
          Get whether or not smoothing is being used
 java.util.Enumeration listOptions()
          Returns an enumeration describing the available options
 double measureNumRules()
          return the number of rules
 void setBuildRegressionTree(boolean newregressionTree)
          Set the value of regressionTree.
protected  void setGenerateRules(boolean u)
          Generate rules (decision list) rather than a tree
 void setMinNumInstances(double minNum)
          Set the minumum number of instances to allow at a leaf node
 void setOptions(java.lang.String[] options)
          Parses a given list of options.
 void setUnpruned(boolean unpruned)
          Use unpruned tree/rules
 void setUseUnsmoothed(boolean s)
          Use unsmoothed predictions
 java.lang.String toString()
          Returns a description of the classifier
 
Methods inherited from class weka.classifiers.Classifier
debugTipText, distributionForInstance, forName, getDebug, makeCopies, setDebug
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

m_instances

private Instances m_instances
the instances covered by the tree/rules


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_ruleSet

protected FastVector m_ruleSet
the rule set


m_generateRules

private boolean m_generateRules
generate a decision list instead of a single tree.


m_unsmoothedPredictions

private boolean m_unsmoothedPredictions
use unsmoothed predictions


m_replaceMissing

private ReplaceMissingValues m_replaceMissing
filter to fill in missing values


m_nominalToBinary

private NominalToBinary m_nominalToBinary
filter to convert nominal attributes to binary


m_saveInstances

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


m_regressionTree

protected boolean m_regressionTree
Make a regression tree/rule instead of a model tree/rule


m_useUnpruned

protected boolean m_useUnpruned
Do not prune tree/rules


m_minNumInstances

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

Constructor Detail

M5Base

public M5Base()
Constructor

Method Detail

listOptions

public java.util.Enumeration listOptions()
Returns an enumeration describing the available options

Specified by:
listOptions in interface OptionHandler
Overrides:
listOptions in class Classifier
Returns:
an enumeration of all the available options

setOptions

public void setOptions(java.lang.String[] options)
                throws java.lang.Exception
Parses a given list of options.

Valid options are:

-U
Use unsmoothed predictions.

-R
Build a regression tree rather than a model tree.

Specified by:
setOptions in interface OptionHandler
Overrides:
setOptions in class Classifier
Parameters:
options - the list of options as an array of strings
Throws:
java.lang.Exception - if an option is not supported

getOptions

public java.lang.String[] getOptions()
Gets the current settings of the classifier.

Specified by:
getOptions in interface OptionHandler
Overrides:
getOptions in class Classifier
Returns:
an array of strings suitable for passing to setOptions

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

setGenerateRules

protected void setGenerateRules(boolean u)
Generate rules (decision list) rather than a tree

Parameters:
u - true if rules are to be generated

getGenerateRules

protected boolean getGenerateRules()
get whether rules are being generated rather than a tree

Returns:
true if rules are to be generated

setUseUnsmoothed

public void setUseUnsmoothed(boolean s)
Use unsmoothed predictions

Parameters:
s - true if unsmoothed predictions are to be used

getUseUnsmoothed

public boolean getUseUnsmoothed()
Get whether or not smoothing is being used

Returns:
true if unsmoothed predictions are to be used

getBuildRegressionTree

public boolean getBuildRegressionTree()
Get the value of regressionTree.

Returns:
Value of regressionTree.

setBuildRegressionTree

public void setBuildRegressionTree(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

buildClassifier

public void buildClassifier(Instances data)
                     throws java.lang.Exception
Generates the classifier.

Specified by:
buildClassifier in class Classifier
Parameters:
data - set of instances serving as training data
Throws:
java.lang.Exception - if the classifier has not been generated successfully

classifyInstance

public double classifyInstance(Instance inst)
                        throws java.lang.Exception
Calculates a prediction for an instance using a set of rules or an M5 model tree

Overrides:
classifyInstance in class Classifier
Parameters:
inst - the instance whos class value is to be predicted
Returns:
the prediction
Throws:
if - a prediction can't be made.
java.lang.Exception - if an error occurred during the prediction

toString

public java.lang.String toString()
Returns a description of the classifier

Returns:
a description of the classifier as a String

enumerateMeasures

public java.util.Enumeration enumerateMeasures()
Returns an enumeration of the additional measure names

Specified by:
enumerateMeasures in interface AdditionalMeasureProducer
Returns:
an enumeration of the measure names

getMeasure

public double getMeasure(java.lang.String additionalMeasureName)
Returns the value of the named measure

Specified by:
getMeasure in interface AdditionalMeasureProducer
Parameters:
additionalMeasureName - the name of the measure to query for its value
Returns:
the value of the named measure
Throws:
java.lang.Exception - if the named measure is not supported

measureNumRules

public double measureNumRules()
return the number of rules

Returns:
the number of rules (same as # linear models & # leaves in the tree)

getM5RootNode

public RuleNode getM5RootNode()