weka.classifiers
Class Stacking

java.lang.Object
  |
  +--weka.classifiers.Classifier
        |
        +--weka.classifiers.Stacking
All Implemented Interfaces:
java.lang.Cloneable, OptionHandler, java.io.Serializable

public class Stacking
extends Classifier
implements OptionHandler

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)

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

Field Summary
protected  Classifier[] m_BaseClassifiers
          The base classifiers.
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
protected  int m_Seed
          Random number seed
 
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 classifyInstance(Instance instance)
          Classifies a given instance using the stacked classifier.
 Classifier getBaseClassifier(int index)
          Gets the specific classifier from the set of base classifiers.
 Classifier[] getBaseClassifiers()
          Gets the list of possible classifers to choose from.
protected  java.lang.String getBaseClassifierSpec(int index)
          Gets the classifier specification string, which contains the class name of the classifier and any options to the classifier
protected  java.lang.String getClassifierSpec(Classifier c)
          Gets the classifier specification string, which contains the class name of the classifier and any options to the classifier
 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.
 int getSeed()
          Gets the random number seed.
 java.util.Enumeration listOptions()
          Returns an enumeration describing the available options
static void main(java.lang.String[] argv)
          Main method for testing this class.
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.
 void setBaseClassifiers(Classifier[] classifiers)
          Sets the list of possible classifers to choose from.
 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.
 void setSeed(int seed)
          Sets the seed for random number generation.
 java.lang.String toString()
          Output a representation of this classifier
 
Methods inherited from class weka.classifiers.Classifier
forName, makeCopies
 
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_BaseClassifiers

protected Classifier[] m_BaseClassifiers
The base classifiers.

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

m_Seed

protected int m_Seed
Random number seed
Constructor Detail

Stacking

public Stacking()
Method Detail

listOptions

public java.util.Enumeration listOptions()
Returns an enumeration describing the available options
Specified by:
listOptions in interface OptionHandler
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:

-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)

Specified by:
setOptions in interface OptionHandler
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
Returns:
an array of strings suitable for passing to setOptions

setSeed

public void setSeed(int seed)
Sets the seed for random number generation.
Parameters:
seed - the random number seed

getSeed

public int getSeed()
Gets the random number seed.
Returns:
the random number seed

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

setBaseClassifiers

public void setBaseClassifiers(Classifier[] classifiers)
Sets the list of possible classifers to choose from.
Parameters:
classifiers - an array of classifiers with all options set.

getBaseClassifiers

public Classifier[] getBaseClassifiers()
Gets the list of possible classifers to choose from.
Returns:
the array of Classifiers

getBaseClassifier

public Classifier getBaseClassifier(int index)
Gets the specific classifier from the set of base classifiers.
Parameters:
index - the index of the classifier to retrieve
Returns:
the classifier

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.
Overrides:
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

classifyInstance

public double classifyInstance(Instance instance)
                        throws java.lang.Exception
Classifies a given instance using the stacked classifier.
Overrides:
classifyInstance in class Classifier
Parameters:
instance - the instance to be classified
Throws:
java.lang.Exception - if instance could not be classified successfully

toString

public java.lang.String toString()
Output a representation of this classifier
Overrides:
toString in class java.lang.Object

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]

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

getBaseClassifierSpec

protected java.lang.String getBaseClassifierSpec(int index)
Gets the classifier specification string, which contains the class name of the classifier and any options to the classifier
Parameters:
index - the index of the classifier string to retrieve, starting from 0.
Returns:
the classifier string, or the empty string if no classifier has been assigned (or the index given is out of range).

getClassifierSpec

protected java.lang.String getClassifierSpec(Classifier c)
Gets the classifier specification string, which contains the class name of the classifier and any options to the classifier
Parameters:
c - the classifier
Returns:
the classifier specification string.

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