Package weka.classifiers.meta
Class Stacking
- All Implemented Interfaces:
Serializable
,Cloneable
,Classifier
,BatchPredictor
,CapabilitiesHandler
,CapabilitiesIgnorer
,CommandlineRunnable
,OptionHandler
,Randomizable
,RevisionHandler
,TechnicalInformationHandler
public class Stacking
extends RandomizableParallelMultipleClassifiersCombiner
implements TechnicalInformationHandler
Combines several classifiers using the stacking method. Can do classification or regression.
For more information, see
David H. Wolpert (1992). Stacked generalization. Neural Networks. 5:241-259. BibTeX:
For more information, see
David H. Wolpert (1992). Stacked generalization. Neural Networks. 5:241-259. BibTeX:
@article{Wolpert1992, author = {David H. Wolpert}, journal = {Neural Networks}, pages = {241-259}, publisher = {Pergamon Press}, title = {Stacked generalization}, volume = {5}, year = {1992} }Valid options are:
-M <scheme specification> Full name of meta classifier, followed by options. (default: "weka.classifiers.rules.Zero")
-X <number of folds> Sets the number of cross-validation folds.
-S <num> Random number seed. (default 1)
-B <classifier specification> Full class name of classifier to include, followed by scheme options. May be specified multiple times. (default: "weka.classifiers.rules.ZeroR")
-D If set, classifier is run in debug mode and may output additional info to the console
- Version:
- $Revision: 15032 $
- Author:
- Eibe Frank (eibe@cs.waikato.ac.nz)
- See Also:
-
Field Summary
Fields inherited from class weka.classifiers.AbstractClassifier
BATCH_SIZE_DEFAULT, NUM_DECIMAL_PLACES_DEFAULT
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Returns true if any of the base classifiers are able to generate batch predictions efficiently and all of them implement BatchPredictor.void
buildClassifier
(Instances data) Builds a classifier using stacking.double[]
distributionForInstance
(Instance instance) Returns estimated class probabilities for the given instance if the class is nominal and a one-element array containing the numeric prediction if the class is numeric.double[][]
distributionsForInstances
(Instances instances) Returns class probabilities for all given instances if the class is nominal or corresponding predicted numeric values if the class is numeric.Returns combined capabilities of the base classifiers, i.e., the capabilities all of them have in common.Gets the meta classifier.int
Gets the number of folds for the cross-validation.String[]
Gets the current settings of the Classifier.Returns the revision string.Returns an instance of a TechnicalInformation object, containing detailed information about the technical background of this class, e.g., paper reference or book this class is based on.Returns a string describing classifierboolean
Returns true if the meta classifier or any of the base classifiers are able to generate batch predictions efficiently and all of them implement BatchPredictor.Returns an enumeration describing the available options.static void
Main method for testing this class.Returns the tip text for this propertyReturns the tip text for this propertyvoid
Perform any teardown stuff that might need to happen after execution.void
Perform any setup stuff that might need to happen before commandline execution.void
setMetaClassifier
(Classifier classifier) Adds meta classifiervoid
setNumFolds
(int numFolds) Sets the number of folds for the cross-validation.void
setOptions
(String[] options) Parses a given list of options.toString()
Output a representation of this classifierMethods inherited from class weka.classifiers.RandomizableParallelMultipleClassifiersCombiner
getSeed, seedTipText, setSeed
Methods inherited from class weka.classifiers.ParallelMultipleClassifiersCombiner
getNumExecutionSlots, numExecutionSlotsTipText, setNumExecutionSlots
Methods inherited from class weka.classifiers.MultipleClassifiersCombiner
classifiersTipText, getClassifier, getClassifiers, setClassifiers
Methods inherited from class weka.classifiers.AbstractClassifier
batchSizeTipText, classifyInstance, debugTipText, doNotCheckCapabilitiesTipText, forName, getBatchSize, getDebug, getDoNotCheckCapabilities, getNumDecimalPlaces, makeCopies, makeCopy, numDecimalPlacesTipText, run, runClassifier, setBatchSize, setDebug, setDoNotCheckCapabilities, setNumDecimalPlaces
-
Constructor Details
-
Stacking
public Stacking()
-
-
Method Details
-
globalInfo
Returns a string describing classifier- Returns:
- a description suitable for displaying in the explorer/experimenter gui
-
getTechnicalInformation
Returns an instance of a TechnicalInformation object, containing detailed information about the technical background of this class, e.g., paper reference or book this class is based on.- Specified by:
getTechnicalInformation
in interfaceTechnicalInformationHandler
- Returns:
- the technical information about this class
-
listOptions
Returns an enumeration describing the available options.- Specified by:
listOptions
in interfaceOptionHandler
- Overrides:
listOptions
in classRandomizableParallelMultipleClassifiersCombiner
- Returns:
- an enumeration of all the available options.
-
setOptions
Parses a given list of options.Valid options are:
-M <scheme specification> Full name of meta classifier, followed by options. (default: "weka.classifiers.rules.Zero")
-X <number of folds> Sets the number of cross-validation folds.
-S <num> Random number seed. (default 1)
-B <classifier specification> Full class name of classifier to include, followed by scheme options. May be specified multiple times. (default: "weka.classifiers.rules.ZeroR")
-D If set, classifier is run in debug mode and may output additional info to the console
- Specified by:
setOptions
in interfaceOptionHandler
- Overrides:
setOptions
in classRandomizableParallelMultipleClassifiersCombiner
- Parameters:
options
- the list of options as an array of strings- Throws:
Exception
- if an option is not supported
-
getOptions
Gets the current settings of the Classifier.- Specified by:
getOptions
in interfaceOptionHandler
- Overrides:
getOptions
in classRandomizableParallelMultipleClassifiersCombiner
- Returns:
- an array of strings suitable for passing to setOptions
-
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
Sets the number of folds for the cross-validation.- Parameters:
numFolds
- the number of folds for the cross-validation- Throws:
Exception
- if parameter illegal
-
metaClassifierTipText
Returns the tip text for this property- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
setMetaClassifier
Adds meta classifier- Parameters:
classifier
- the classifier with all options set.
-
getMetaClassifier
Gets the meta classifier.- Returns:
- the meta classifier
-
getCapabilities
Returns combined capabilities of the base classifiers, i.e., the capabilities all of them have in common.- Specified by:
getCapabilities
in interfaceCapabilitiesHandler
- Specified by:
getCapabilities
in interfaceClassifier
- Overrides:
getCapabilities
in classMultipleClassifiersCombiner
- Returns:
- the capabilities of the base classifiers
- See Also:
-
implementsMoreEfficientBatchPrediction
public boolean implementsMoreEfficientBatchPrediction()Returns true if the meta classifier or any of the base classifiers are able to generate batch predictions efficiently and all of them implement BatchPredictor.- Specified by:
implementsMoreEfficientBatchPrediction
in interfaceBatchPredictor
- Overrides:
implementsMoreEfficientBatchPrediction
in classAbstractClassifier
- Returns:
- true if batch prediction can be done efficiently
-
baseClassifiersImplementMoreEfficientBatchPrediction
public boolean baseClassifiersImplementMoreEfficientBatchPrediction()Returns true if any of the base classifiers are able to generate batch predictions efficiently and all of them implement BatchPredictor.- Returns:
- true if the base classifiers can do batch prediction efficiently
-
buildClassifier
Builds a classifier using stacking. The base classifiers' output is fed into the meta classifier to make the final decision. The training data for the meta classifier is generated using (stratified) cross-validation.- Specified by:
buildClassifier
in interfaceClassifier
- Overrides:
buildClassifier
in classParallelMultipleClassifiersCombiner
- Parameters:
data
- the training data to be used for generating the stacked classifier.- Throws:
Exception
- if the classifier could not be built successfully
-
distributionForInstance
Returns estimated class probabilities for the given instance if the class is nominal and a one-element array containing the numeric prediction if the class is numeric.- Specified by:
distributionForInstance
in interfaceClassifier
- Overrides:
distributionForInstance
in classAbstractClassifier
- Parameters:
instance
- the instance to be classified- Returns:
- the distribution
- Throws:
Exception
- if instance could not be classified successfully
-
distributionsForInstances
Returns class probabilities for all given instances if the class is nominal or corresponding predicted numeric values if the class is numeric. The meta classifier must implement BatchPredictor, otherwise an exception will be thrown.- Specified by:
distributionsForInstances
in interfaceBatchPredictor
- Overrides:
distributionsForInstances
in classAbstractClassifier
- Parameters:
instances
- the instance sto be classified- Returns:
- the distributions
- Throws:
Exception
- if instances could not be classified successfully
-
toString
Output a representation of this classifier -
preExecution
Description copied from class:AbstractClassifier
Perform any setup stuff that might need to happen before commandline execution. Subclasses should override if they need to do something here- Specified by:
preExecution
in interfaceCommandlineRunnable
- Overrides:
preExecution
in classMultipleClassifiersCombiner
- Throws:
Exception
- if a problem occurs during setup
-
postExecution
Description copied from class:AbstractClassifier
Perform any teardown stuff that might need to happen after execution. Subclasses should override if they need to do something here- Specified by:
postExecution
in interfaceCommandlineRunnable
- Overrides:
postExecution
in classMultipleClassifiersCombiner
- Throws:
Exception
- if a problem occurs during teardown
-
getRevision
Returns the revision string.- Specified by:
getRevision
in interfaceRevisionHandler
- Overrides:
getRevision
in classAbstractClassifier
- Returns:
- the revision
-
main
Main method for testing this class.- Parameters:
argv
- should contain the following arguments: -t training file [-T test file] [-c class index]
-