weka.classifiers.lazy
Class LBR

java.lang.Object
  extended byweka.classifiers.Classifier
      extended byweka.classifiers.lazy.LBR
All Implemented Interfaces:
java.lang.Cloneable, OptionHandler, java.io.Serializable

public class LBR
extends Classifier

Lazy Bayesian Rules implement a lazy learning approach to lessening the attribute-independence assumption of naive Bayes. For each object to be classified, LBR selects a set of attributes for which the attribute independence assumption should not be made. All remaining attributes are treated as independent of each other given the class and the selected set of attributes. LBR has demonstrated very high accuracy. Its training time is low but its classification time is high due to the use of a lazy methodology. This implementation does not include caching, that can substantially reduce classification time when multiple classifications are performed for a single training set. For more information, see

Zijian Zheng & G. Webb, (2000). Lazy Learning of Bayesian Rules. Machine Learning, 41(1): 53-84.

Version:
$Revision: 1.4 $
Author:
Zhihai Wang (zhw@deakin.edu.au) : July 2001 implemented the algorithm, Jason Wells (wells@deakin.edu.au) : November 2001 added instance referencing via indexes
See Also:
Serialized Form

Nested Class Summary
 class LBR.Indexes
          Class for handling instances and the associated attributes.
 
Field Summary
protected  int bestCnt
           
protected  int forCnt
           
protected  java.util.ArrayList leftHand
           
protected  int[][][] m_Counts
          All the counts for nominal attributes.
protected  boolean[] m_ErrorFlags
           
protected  int m_Errors
           
protected  Instances m_Instances
          The set of instances used for current training.
protected  boolean m_NCV
           
protected  int m_numAtts
          number of attributes for the dataset
protected  int m_Number
           
protected  int m_NumberOfInstances
           
protected  int m_numClasses
          number of classes for dataset
protected  int m_numInsts
          number of instances in dataset
protected  int[] m_Priors
          The prior probabilities of the classes.
protected  int m_RemainderErrors
           
protected  LBR.Indexes m_subInstances
           
protected  boolean[] m_subOldErrorFlags
           
protected  int[][][] m_tCounts
          All the counts for nominal attributes.
protected  int[] m_tPriors
          The prior probabilities of the classes.
protected  double[] posteriorsArray
           
protected static double SIGNLOWER
           
protected  int tempCnt
           
protected  LBR.Indexes tempSubInstances
           
protected  int whileCnt
           
 
Fields inherited from class weka.classifiers.Classifier
m_Debug
 
Constructor Summary
LBR()
           
 
Method Summary
 double binomP(double r, double n, double p)
          Significance test binomp:
 void buildClassifier(Instances instances)
          For lazy learning, building classifier is only to prepare their inputs until classification time.
 double[] distributionForInstance(Instance testInstance)
          Calculates the class membership probabilities for the given test instance.
 java.lang.String globalInfo()
           
 int leaveOneOut(LBR.Indexes instanceIndex, int[][][] counts, int[] priors, boolean[] errorFlags)
          Leave-one-out strategy.
 double[] localDistributionForInstance(Instance instance, LBR.Indexes instanceIndex)
          Calculates the class membership probabilities.
 void localNaiveBayes(LBR.Indexes instanceIndex)
          Class for building and using a simple Naive Bayes classifier.
static void main(java.lang.String[] argv)
          Main method for testing this class.
 java.lang.String toString()
          Returns a description of the classifier.
 
Methods inherited from class weka.classifiers.Classifier
classifyInstance, debugTipText, forName, getDebug, getOptions, listOptions, makeCopies, setDebug, setOptions
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

m_Counts

protected int[][][] m_Counts
All the counts for nominal attributes.


m_tCounts

protected int[][][] m_tCounts
All the counts for nominal attributes.


m_Priors

protected int[] m_Priors
The prior probabilities of the classes.


m_tPriors

protected int[] m_tPriors
The prior probabilities of the classes.


m_numAtts

protected int m_numAtts
number of attributes for the dataset


m_numClasses

protected int m_numClasses
number of classes for dataset


m_numInsts

protected int m_numInsts
number of instances in dataset


m_Instances

protected Instances m_Instances
The set of instances used for current training.


m_Errors

protected int m_Errors

m_ErrorFlags

protected boolean[] m_ErrorFlags

leftHand

protected java.util.ArrayList leftHand

SIGNLOWER

protected static final double SIGNLOWER
See Also:
Constant Field Values

m_subOldErrorFlags

protected boolean[] m_subOldErrorFlags

m_RemainderErrors

protected int m_RemainderErrors

m_Number

protected int m_Number

m_NumberOfInstances

protected int m_NumberOfInstances

m_NCV

protected boolean m_NCV

m_subInstances

protected LBR.Indexes m_subInstances

tempSubInstances

protected LBR.Indexes tempSubInstances

posteriorsArray

protected double[] posteriorsArray

bestCnt

protected int bestCnt

tempCnt

protected int tempCnt

forCnt

protected int forCnt

whileCnt

protected int whileCnt
Constructor Detail

LBR

public LBR()
Method Detail

globalInfo

public java.lang.String globalInfo()
Returns:
a description of the classifier suitable for displaying in the explorer/experimenter gui

buildClassifier

public void buildClassifier(Instances instances)
                     throws java.lang.Exception
For lazy learning, building classifier is only to prepare their inputs until classification time.

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

distributionForInstance

public double[] distributionForInstance(Instance testInstance)
                                 throws java.lang.Exception
Calculates the class membership probabilities for the given test instance. This is the most important method for Lazy Bayesian Rule algorithm.

Overrides:
distributionForInstance in class Classifier
Parameters:
testInstance - the instance to be classified
Returns:
predicted class probability distribution
Throws:
java.lang.Exception - if distribution can't be computed

toString

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

Returns:
a description of the classifier as a string.

leaveOneOut

public int leaveOneOut(LBR.Indexes instanceIndex,
                       int[][][] counts,
                       int[] priors,
                       boolean[] errorFlags)
                throws java.lang.Exception
Leave-one-out strategy. For a given sample data set with n instances, using (n - 1) instances by leaving one out and tested on the single remaining case. This is repeated n times in turn. The final "Error" is the sum of the instances to be classified incorrectly.

Parameters:
counts - serving as all the counts of training data.
priors - serving as the number of instances in each class.
Returns:
error flag array about each instance.
Throws:
java.lang.Exception

localNaiveBayes

public void localNaiveBayes(LBR.Indexes instanceIndex)
                     throws java.lang.Exception
Class for building and using a simple Naive Bayes classifier. For more information, see

Richard Duda and Peter Hart (1973).Pattern Classification and Scene Analysis. Wiley, New York. This method only get m_Counts and m_Priors.

Throws:
java.lang.Exception - if m_Counts and m_Priors have not been generated successfully

localDistributionForInstance

public double[] localDistributionForInstance(Instance instance,
                                             LBR.Indexes instanceIndex)
                                      throws java.lang.Exception
Calculates the class membership probabilities. for the given test instance.

Parameters:
instance - the instance to be classified
Returns:
predicted class probability distribution
Throws:
java.lang.Exception - if distribution can't be computed

binomP

public double binomP(double r,
                     double n,
                     double p)
              throws java.lang.Exception
Significance test binomp:

Returns:
returns the probability of obtaining r or fewer out of n if the probability of an event is p.
Throws:
java.lang.Exception

main

public static void main(java.lang.String[] argv)
Main method for testing this class.

Parameters:
argv - the options