All Packages  Class Hierarchy  This Package  Previous  Next  Index  WEKA's home

Class weka.classifiers.meta.Bagging

java.lang.Object
    |
    +----weka.classifiers.Classifier
            |
            +----weka.classifiers.DistributionClassifier
                    |
                    +----weka.classifiers.meta.Bagging

public class Bagging
extends DistributionClassifier
implements OptionHandler, WeightedInstancesHandler, Randomizable, AdditionalMeasureProducer
Class for bagging a classifier. For more information, see

Leo Breiman (1996). Bagging predictors. Machine Learning, 24(2):123-140.

Valid options are:

-W classname
Specify the full class name of a weak classifier as the basis for bagging (required).

-I num
Set the number of bagging iterations (default 10).

-S seed
Random number seed for resampling (default 1).

-P num
Size of each bag, as a percentage of the training size (default 100).

-O
Compute out of bag error.

Options after -- are passed to the designated classifier.

Version:
$Revision: 1.23 $
Author:
Eibe Frank (eibe@cs.waikato.ac.nz)
Author:
Len Trigg (len@reeltwo.com)
Author:
Richard Kirkby (rkirkby@cs.waikato.ac.nz)

Constructor Index

 o Bagging()
 

Method Index

 o buildClassifier(Instances)
Bagging method.
 o distributionForInstance(Instance)
Calculates the class membership probabilities for the given test instance.
 o enumerateMeasures()
Returns an enumeration of the additional measure names.
 o getBagSizePercent()
Gets the size of each bag, as a percentage of the training set size.
 o getCalcOutOfBag()
Get whether the out of bag error is calculated.
 o getClassifier()
Get the classifier used as the classifier
 o getMeasure(String)
Returns the value of the named measure.
 o getNumIterations()
Gets the number of bagging iterations
 o getOptions()
Gets the current settings of the Classifier.
 o getSeed()
Gets the seed for the random number generations
 o listOptions()
Returns an enumeration describing the available options.
 o main(String[])
Main method for testing this class.
 o measureOutOfBagError()
Gets the out of bag error that was calculated as the classifier was built.
 o setBagSizePercent(int)
Sets the size of each bag, as a percentage of the training set size.
 o setCalcOutOfBag(boolean)
Set whether the out of bag error is calculated.
 o setClassifier(Classifier)
Set the classifier for bagging.
 o setNumIterations(int)
Sets the number of bagging iterations
 o setOptions(String[])
Parses a given list of options.
 o setSeed(int)
Set the seed for random number generation.
 o toString()
Returns description of the bagged classifier.

Constructor Detail

 o Bagging
public Bagging()

Method Detail

 o listOptions
public java.util.Enumeration listOptions()
          Returns an enumeration describing the available options.
Returns:
an enumeration of all the available options.
 o setOptions
public void setOptions(java.lang.String options[]) throws java.lang.Exception
          Parses a given list of options. Valid options are:

-W classname
Specify the full class name of a weak classifier as the basis for bagging (required).

-I num
Set the number of bagging iterations (default 10).

-S seed
Random number seed for resampling (default 1).

-P num
Size of each bag, as a percentage of the training size (default 100).

-O
Compute out of bag error.

Options after -- are passed to the designated classifier.

Parameters:
options - the list of options as an array of strings
Throws:
java.lang.Exception - if an option is not supported
 o getOptions
public java.lang.String[] getOptions()
          Gets the current settings of the Classifier.
Returns:
an array of strings suitable for passing to setOptions
 o setClassifier
public void setClassifier(Classifier newClassifier)
          Set the classifier for bagging.
Parameters:
newClassifier - the Classifier to use.
 o getClassifier
public Classifier getClassifier()
          Get the classifier used as the classifier
Returns:
the classifier used as the classifier
 o getBagSizePercent
public int getBagSizePercent()
          Gets the size of each bag, as a percentage of the training set size.
Returns:
the bag size, as a percentage.
 o setBagSizePercent
public void setBagSizePercent(int newBagSizePercent)
          Sets the size of each bag, as a percentage of the training set size.
Parameters:
newBagSizePercent - the bag size, as a percentage.
 o setNumIterations
public void setNumIterations(int numIterations)
          Sets the number of bagging iterations
 o getNumIterations
public int getNumIterations()
          Gets the number of bagging iterations
Returns:
the maximum number of bagging iterations
 o setSeed
public void setSeed(int seed)
          Set the seed for random number generation.
Parameters:
seed - the seed
 o getSeed
public int getSeed()
          Gets the seed for the random number generations
Returns:
the seed for the random number generation
 o setCalcOutOfBag
public void setCalcOutOfBag(boolean calcOutOfBag)
          Set whether the out of bag error is calculated.
Parameters:
calcOutOfBag - whether to calculate the out of bag error
 o getCalcOutOfBag
public boolean getCalcOutOfBag()
          Get whether the out of bag error is calculated.
Returns:
whether the out of bag error is calculated
 o measureOutOfBagError
public double measureOutOfBagError()
          Gets the out of bag error that was calculated as the classifier was built.
Returns:
the out of bag error
 o enumerateMeasures
public java.util.Enumeration enumerateMeasures()
          Returns an enumeration of the additional measure names.
Returns:
an enumeration of the measure names
 o getMeasure
public double getMeasure(java.lang.String additionalMeasureName)
          Returns the value of the named measure.
Parameters:
measureName - the name of the measure to query for its value
Returns:
the value of the named measure
Throws:
java.lang.IllegalArgumentException - if the named measure is not supported
 o buildClassifier
public void buildClassifier(Instances data) throws java.lang.Exception
          Bagging method.
Parameters:
data - the training data to be used for generating the bagged classifier.
Throws:
java.lang.Exception - if the classifier could not be built successfully
Overrides:
buildClassifier in class Classifier
 o distributionForInstance
public double[] distributionForInstance(Instance instance) throws java.lang.Exception
          Calculates the class membership probabilities for the given test instance.
Parameters:
instance - the instance to be classified
Returns:
preedicted class probability distribution
Throws:
java.lang.Exception - if distribution can't be computed successfully
Overrides:
distributionForInstance in class DistributionClassifier
 o toString
public java.lang.String toString()
          Returns description of the bagged classifier.
Returns:
description of the bagged classifier as a string
Overrides:
toString in class java.lang.Object
 o main
public static void main(java.lang.String argv[])
          Main method for testing this class.
Parameters:
argv - the options

All Packages  Class Hierarchy  This Package  Previous  Next  Index  WEKA's home