weka.classifiers.rules
Class ConjunctiveRule

java.lang.Object
  extended byweka.classifiers.Classifier
      extended byweka.classifiers.rules.ConjunctiveRule
All Implemented Interfaces:
java.lang.Cloneable, OptionHandler, java.io.Serializable, WeightedInstancesHandler

public class ConjunctiveRule
extends Classifier
implements OptionHandler, WeightedInstancesHandler

This class implements a single conjunctive rule learner that can predict for numeric and nominal class labels.

A rule consists of antecedents "AND"ed together and the consequent (class value) for the classification/regression. In this case, the consequent is the distribution of the available classes (or numeric value) in the dataset. If the test instance is not covered by this rule, then it's predicted using the default class distributions/value of the data not covered by the rule in the training data.
This learner selects an antecedent by computing the Information Gain of each antecendent and prunes the generated rule using Reduced Error Prunning (REP).

For classification, the Information of one antecedent is the weighted average of the entropies of both the data covered and not covered by the rule.
For regression, the Information is the weighted average of the mean-squared errors of both the data covered and not covered by the rule.

In pruning, weighted average of accuracy rate of the pruning data is used for classification while the weighted average of the mean-squared errors of the pruning data is used for regression.

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

Nested Class Summary
private  class ConjunctiveRule.Antd
          The single antecedent in the rule, which is composed of an attribute and the corresponding value.
(package private)  class ConjunctiveRule.NominalAntd
          The antecedent with nominal attribute
private  class ConjunctiveRule.NumericAntd
          The antecedent with numeric attribute
 
Field Summary
protected  FastVector m_Antds
          The vector of antecedents of this rule
private  Attribute m_ClassAttribute
          The class attribute of the data
protected  double[] m_Cnsqt
          The consequent of this rule
protected  double[] m_DefDstr
          The default rule distribution of the data not covered
private  int m_Folds
          The number of folds to split data into Grow and Prune for REP
private  boolean m_IsExclude
          Whether to use exlusive expressions for nominal attributes
private  double m_MinNo
          The minimal number of instance weights within a split
private  int m_NumAntds
          The number of antecedents in pre-pruning
private  int m_NumClasses
          Number of classes in the training data
private  java.util.Random m_Random
          The Random object used for randomization
private  long m_Seed
          The seed to perform randomization
private  FastVector m_Targets
          The predicted classes recorded for each antecedent in the growing data
 
Fields inherited from class weka.classifiers.Classifier
m_Debug
 
Constructor Summary
ConjunctiveRule()
           
 
Method Summary
 void buildClassifier(Instances instances)
          Builds a single rule learner with REP dealing with nominal classes or numeric classes.
private  double computeAccu(Instances data, int clas)
          Private function to compute number of accurate instances based on the specified predicted class
private  Instances[] computeInfoGain(Instances instances, double defInfo, ConjunctiveRule.Antd antd)
          Compute the best information gain for the specified antecedent
 double[] distributionForInstance(Instance instance)
          Computes class distribution for the given instance.
 java.lang.String exclusiveTipText()
          Returns the tip text for this property
 java.lang.String foldsTipText()
          Returns the tip text for this property
 boolean getExclusive()
           
 int getFolds()
           
 double getMinNo()
           
 int getNumAntds()
           
 java.lang.String[] getOptions()
          Gets the current settings of the Classifier.
 long getSeed()
           
 java.lang.String globalInfo()
          Returns a string describing classifier
private  void grow(Instances data)
          Build one rule using the growing data
 boolean hasAntds()
          Whether this rule has antecedents, i.e. whether it is a default rule
 boolean isCover(Instance datum)
          Whether the instance covered by this rule
 java.util.Enumeration listOptions()
          Returns an enumeration describing the available options Valid options are: -N number
Set number of folds for REP.
static void main(java.lang.String[] args)
          Main method.
private  double meanSquaredError(Instances data, double mean)
          Private function to compute the squared error of the specified data and the specified mean
 java.lang.String minNoTipText()
          Returns the tip text for this property
 java.lang.String numAntdsTipText()
          Returns the tip text for this property
private  void prune(Instances pruneData)
          Prune the rule using the pruning data.
 java.lang.String seedTipText()
          Returns the tip text for this property
 void setExclusive(boolean e)
           
 void setFolds(int folds)
           
 void setMinNo(double m)
           
 void setNumAntds(int n)
           
 void setOptions(java.lang.String[] options)
          Parses a given list of options.
 void setSeed(long s)
           
 java.lang.String toString()
          Prints this rule
 java.lang.String toString(java.lang.String att, java.lang.String cl)
          Prints this rule with the specified class label
 
Methods inherited from class weka.classifiers.Classifier
classifyInstance, debugTipText, forName, getDebug, makeCopies, setDebug
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

m_Folds

private int m_Folds
The number of folds to split data into Grow and Prune for REP


m_ClassAttribute

private Attribute m_ClassAttribute
The class attribute of the data


m_Antds

protected FastVector m_Antds
The vector of antecedents of this rule


m_DefDstr

protected double[] m_DefDstr
The default rule distribution of the data not covered


m_Cnsqt

protected double[] m_Cnsqt
The consequent of this rule


m_NumClasses

private int m_NumClasses
Number of classes in the training data


m_Seed

private long m_Seed
The seed to perform randomization


m_Random

private java.util.Random m_Random
The Random object used for randomization


m_Targets

private FastVector m_Targets
The predicted classes recorded for each antecedent in the growing data


m_IsExclude

private boolean m_IsExclude
Whether to use exlusive expressions for nominal attributes


m_MinNo

private double m_MinNo
The minimal number of instance weights within a split


m_NumAntds

private int m_NumAntds
The number of antecedents in pre-pruning

Constructor Detail

ConjunctiveRule

public ConjunctiveRule()
Method Detail

globalInfo

public java.lang.String globalInfo()
Returns a string describing classifier

Returns:
a description suitable for displaying in the explorer/experimenter gui

listOptions

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

-N number
Set number of folds for REP. One fold is used as the pruning set. (Default: 3)

-R
Set if NOT randomize the data before split to growing and pruning data. If NOT set, the seed of randomization is specified by the -S option. (Default: randomize)

-S
Seed of randomization. (Default: 1)

-E
Set whether consider the exclusive expressions for nominal attribute split. (Default: false)

-M number
Set the minimal weights of instances within a split. (Default: 2)

-P number
Set the number of antecedents allowed in the rule if pre-pruning is used. If this value is other than -1, then pre-pruning will be used, otherwise the rule uses REP. (Default: -1)

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.

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

foldsTipText

public java.lang.String foldsTipText()
Returns the tip text for this property

Returns:
tip text for this property suitable for displaying in the explorer/experimenter gui

setFolds

public void setFolds(int folds)

getFolds

public int getFolds()

seedTipText

public java.lang.String seedTipText()
Returns the tip text for this property

Returns:
tip text for this property suitable for displaying in the explorer/experimenter gui

setSeed

public void setSeed(long s)

getSeed

public long getSeed()

exclusiveTipText

public java.lang.String exclusiveTipText()
Returns the tip text for this property

Returns:
tip text for this property suitable for displaying in the explorer/experimenter gui

getExclusive

public boolean getExclusive()

setExclusive

public void setExclusive(boolean e)

minNoTipText

public java.lang.String minNoTipText()
Returns the tip text for this property

Returns:
tip text for this property suitable for displaying in the explorer/experimenter gui

setMinNo

public void setMinNo(double m)

getMinNo

public double getMinNo()

numAntdsTipText

public java.lang.String numAntdsTipText()
Returns the tip text for this property

Returns:
tip text for this property suitable for displaying in the explorer/experimenter gui

setNumAntds

public void setNumAntds(int n)

getNumAntds

public int getNumAntds()

buildClassifier

public void buildClassifier(Instances instances)
                     throws java.lang.Exception
Builds a single rule learner with REP dealing with nominal classes or numeric classes. For nominal classes, this rule learner predicts a distribution on the classes. For numeric classes, this learner predicts a single value.

Specified by:
buildClassifier in class Classifier
Parameters:
instances - the training data
Throws:
java.lang.Exception - if classifier can't be built successfully

distributionForInstance

public double[] distributionForInstance(Instance instance)
                                 throws java.lang.Exception
Computes class distribution for the given instance.

Overrides:
distributionForInstance in class Classifier
Parameters:
instance - the instance for which distribution is to be computed
Returns:
the class distribution for the given instance
Throws:
java.lang.Exception - if distribution could not be computed successfully

isCover

public boolean isCover(Instance datum)
Whether the instance covered by this rule

Returns:
the boolean value indicating whether the instance is covered by this rule

hasAntds

public boolean hasAntds()
Whether this rule has antecedents, i.e. whether it is a default rule

Returns:
the boolean value indicating whether the rule has antecedents

grow

private void grow(Instances data)
Build one rule using the growing data

Parameters:
data - the growing data used to build the rule

computeInfoGain

private Instances[] computeInfoGain(Instances instances,
                                    double defInfo,
                                    ConjunctiveRule.Antd antd)
Compute the best information gain for the specified antecedent

Parameters:
defInfo - the default information of data
antd - the specific antecedent
Returns:
the data covered and not covered by the antecedent

prune

private void prune(Instances pruneData)
Prune the rule using the pruning data. The weighted average of accuracy rate/mean-squared error is used to prune the rule.

Parameters:
pruneData - the pruning data used to prune the rule

computeAccu

private double computeAccu(Instances data,
                           int clas)
Private function to compute number of accurate instances based on the specified predicted class

Parameters:
data - the data in question
clas - the predicted class
Returns:
the default accuracy number

meanSquaredError

private double meanSquaredError(Instances data,
                                double mean)
Private function to compute the squared error of the specified data and the specified mean

Parameters:
data - the data in question
mean - the specified mean
Returns:
the default mean-squared error

toString

public java.lang.String toString(java.lang.String att,
                                 java.lang.String cl)
Prints this rule with the specified class label

Parameters:
att - the string standing for attribute in the consequent of this rule
cl - the string standing for value in the consequent of this rule
Returns:
a textual description of this rule with the specified class label

toString

public java.lang.String toString()
Prints this rule

Returns:
a textual description of this rule

main

public static void main(java.lang.String[] args)
Main method.

Parameters:
args - the options for the classifier