weka.classifiers.meta
Class Stacking

java.lang.Object
  extended byweka.classifiers.Classifier
      extended byweka.classifiers.MultipleClassifiersCombiner
          extended byweka.classifiers.RandomizableMultipleClassifiersCombiner
              extended byweka.classifiers.meta.Stacking
All Implemented Interfaces:
java.lang.Cloneable, OptionHandler, Randomizable, java.io.Serializable
Direct Known Subclasses:
Grading, StackingC

public class Stacking
extends RandomizableMultipleClassifiersCombiner

Implements stacking. For more information, see

David H. Wolpert (1992). Stacked generalization. Neural Networks, 5:241-259, Pergamon Press.

Valid options are:

-X num_folds
The number of folds for the cross-validation (default 10).

-S seed
Random number seed (default 1).

-B classifierstring
Classifierstring should contain the full class name of a base scheme followed by options to the classifier. (required, option should be used once for each classifier).

-M classifierstring
Classifierstring for the meta classifier. Same format as for base classifiers. (required)

Version:
$Revision: 1.22 $
Author:
Eibe Frank (eibe@cs.waikato.ac.nz)
See Also:
Serialized Form

Field Summary
protected  Instances m_BaseFormat
          Format for base data
protected  Classifier m_MetaClassifier
          The meta classifier
protected  Instances m_MetaFormat
          Format for meta data
protected  int m_NumFolds
          Set the number of folds for the cross-validation
 
Fields inherited from class weka.classifiers.RandomizableMultipleClassifiersCombiner
m_Seed
 
Fields inherited from class weka.classifiers.MultipleClassifiersCombiner
m_Classifiers
 
Fields inherited from class weka.classifiers.Classifier
m_Debug
 
Constructor Summary
Stacking()
           
 
Method Summary
 void buildClassifier(Instances data)
          Buildclassifier selects a classifier from the set of classifiers by minimising error on the training data.
 double[] distributionForInstance(Instance instance)
          Returns class probabilities.
protected  void generateMetaLevel(Instances newData, java.util.Random random)
          Generates the meta data
 Classifier getMetaClassifier()
          Gets the meta classifier.
 int getNumFolds()
          Gets the number of folds for the cross-validation.
 java.lang.String[] getOptions()
          Gets the current settings of the Classifier.
 java.lang.String globalInfo()
          Returns a string describing classifier
 java.util.Enumeration listOptions()
          Returns an enumeration describing the available options.
static void main(java.lang.String[] argv)
          Main method for testing this class.
 java.lang.String metaClassifierTipText()
          Returns the tip text for this property
protected  Instances metaFormat(Instances instances)
          Makes the format for the level-1 data.
protected  Instance metaInstance(Instance instance)
          Makes a level-1 instance from the given instance.
protected  java.lang.String metaOption()
          String describing option for setting meta classifier
 java.lang.String numFoldsTipText()
          Returns the tip text for this property
protected  void processMetaOptions(java.lang.String[] options)
          Process options setting meta classifier.
 void setMetaClassifier(Classifier classifier)
          Adds meta classifier
 void setNumFolds(int numFolds)
          Sets the number of folds for the cross-validation.
 void setOptions(java.lang.String[] options)
          Parses a given list of options.
 java.lang.String toString()
          Output a representation of this classifier
 
Methods inherited from class weka.classifiers.RandomizableMultipleClassifiersCombiner
getSeed, seedTipText, setSeed
 
Methods inherited from class weka.classifiers.MultipleClassifiersCombiner
classifiersTipText, getClassifier, getClassifiers, getClassifierSpec, setClassifiers
 
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_MetaClassifier

protected Classifier m_MetaClassifier
The meta classifier


m_MetaFormat

protected Instances m_MetaFormat
Format for meta data


m_BaseFormat

protected Instances m_BaseFormat
Format for base data


m_NumFolds

protected int m_NumFolds
Set the number of folds for the cross-validation

Constructor Detail

Stacking

public Stacking()
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.

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

metaOption

protected java.lang.String metaOption()
String describing option for setting meta classifier


setOptions

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

-X num_folds
The number of folds for the cross-validation (default 10).

-S seed
Random number seed (default 1).

-B classifierstring
Classifierstring should contain the full class name of a base scheme followed by options to the classifier. (required, option should be used once for each classifier).

-M classifierstring
Classifierstring for the meta classifier. Same format as for base classifiers. (default: weka.classifiers.rules.ZeroR)

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

processMetaOptions

protected void processMetaOptions(java.lang.String[] options)
                           throws java.lang.Exception
Process options setting meta classifier.

Throws:
java.lang.Exception

getOptions

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

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

numFoldsTipText

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

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

getNumFolds

public int getNumFolds()
Gets the number of folds for the cross-validation.

Returns:
the number of folds for the cross-validation

setNumFolds

public void setNumFolds(int numFolds)
                 throws java.lang.Exception
Sets the number of folds for the cross-validation.

Parameters:
numFolds - the number of folds for the cross-validation
Throws:
java.lang.Exception - if parameter illegal

metaClassifierTipText

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

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

setMetaClassifier

public void setMetaClassifier(Classifier classifier)
Adds meta classifier

Parameters:
classifier - the classifier with all options set.

getMetaClassifier

public Classifier getMetaClassifier()
Gets the meta classifier.

Returns:
the meta classifier

buildClassifier

public void buildClassifier(Instances data)
                     throws java.lang.Exception
Buildclassifier selects a classifier from the set of classifiers by minimising error on the training data.

Specified by:
buildClassifier in class Classifier
Parameters:
data - the training data to be used for generating the boosted classifier.
Throws:
java.lang.Exception - if the classifier could not be built successfully

generateMetaLevel

protected void generateMetaLevel(Instances newData,
                                 java.util.Random random)
                          throws java.lang.Exception
Generates the meta data

Throws:
java.lang.Exception

distributionForInstance

public double[] distributionForInstance(Instance instance)
                                 throws java.lang.Exception
Returns class probabilities.

Overrides:
distributionForInstance in class Classifier
Parameters:
instance - the instance to be classified
Returns:
an array containing the estimated membership probabilities of the test instance in each class or the numeric prediction
Throws:
java.lang.Exception - if instance could not be classified successfully

toString

public java.lang.String toString()
Output a representation of this classifier


metaFormat

protected Instances metaFormat(Instances instances)
                        throws java.lang.Exception
Makes the format for the level-1 data.

Parameters:
instances - the level-0 format
Returns:
the format for the meta data
Throws:
java.lang.Exception

metaInstance

protected Instance metaInstance(Instance instance)
                         throws java.lang.Exception
Makes a level-1 instance from the given instance.

Parameters:
instance - the instance to be transformed
Returns:
the level-1 instance
Throws:
java.lang.Exception

main

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

Parameters:
argv - should contain the following arguments: -t training file [-T test file] [-c class index]