Package weka.classifiers.meta
Class MultiClassClassifier
- java.lang.Object
-
- weka.classifiers.AbstractClassifier
-
- weka.classifiers.SingleClassifierEnhancer
-
- weka.classifiers.RandomizableSingleClassifierEnhancer
-
- weka.classifiers.meta.MultiClassClassifier
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable,Classifier,BatchPredictor,CapabilitiesHandler,CapabilitiesIgnorer,CommandlineRunnable,OptionHandler,Randomizable,RevisionHandler,WeightedInstancesHandler
- Direct Known Subclasses:
MultiClassClassifierUpdateable
public class MultiClassClassifier extends RandomizableSingleClassifierEnhancer implements OptionHandler, WeightedInstancesHandler
A metaclassifier for handling multi-class datasets with 2-class classifiers. This classifier is also capable of applying error correcting output codes for increased accuracy. If the base classifier cannot handle instance weights, and the instance weights are not uniform, the data will be resampled with replacement based on the weights before being passed to the base classifier. Valid options are:-M <num> Sets the method to use. Valid values are 0 (1-against-all), 1 (random codes), 2 (exhaustive code), and 3 (1-against-1). (default 0)
-R <num> Sets the multiplier when using random codes. (default 2.0)
-P Use pairwise coupling (only has an effect for 1-against1)
-L Use log loss decoding for random and exhaustive codes.
-S <num> Random number seed. (default 1)
-D If set, classifier is run in debug mode and may output additional info to the console
-W Full name of base classifier. (default: weka.classifiers.functions.Logistic)
Options specific to classifier weka.classifiers.functions.Logistic:
-D Turn on debugging output.
-R <ridge> Set the ridge in the log-likelihood.
-M <number> Set the maximum number of iterations (default -1, until convergence).
- Version:
- $Revision: 15476 $
- Author:
- Eibe Frank (eibe@cs.waikato.ac.nz), Len Trigg (len@reeltwo.com), Richard Kirkby (rkirkby@cs.waikato.ac.nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static intMETHOD_1_AGAINST_11-against-1static intMETHOD_1_AGAINST_ALL1-against-allstatic intMETHOD_ERROR_EXHAUSTIVEexhaustive correction codestatic intMETHOD_ERROR_RANDOMrandom correction codestatic Tag[]TAGS_METHODThe error correction modes-
Fields inherited from class weka.classifiers.AbstractClassifier
BATCH_SIZE_DEFAULT, NUM_DECIMAL_PLACES_DEFAULT
-
-
Constructor Summary
Constructors Constructor Description MultiClassClassifier()Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbuildClassifier(Instances insts)Builds the classifiers.double[]distributionForInstance(Instance inst)Returns the distribution for an instance.CapabilitiesgetCapabilities()Returns default capabilities of the classifier.booleangetLogLossDecoding()Whether log loss decoding is used for random or exhaustive codes.SelectedTaggetMethod()Gets the method used.java.lang.String[]getOptions()Gets the current settings of the Classifier.doublegetRandomWidthFactor()Gets the multiplier when generating random codes.java.lang.StringgetRevision()Returns the revision string.booleangetUsePairwiseCoupling()Gets whether to use pairwise coupling with 1-vs-1 classification to improve probability estimates.java.lang.StringglobalInfo()double[]individualPredictions(Instance inst)Returns the individual predictions of the base classifiers for an instance.java.util.Enumeration<Option>listOptions()Returns an enumeration describing the available optionsjava.lang.StringlogLossDecodingTipText()static voidmain(java.lang.String[] argv)Main method for testing this class.java.lang.StringmethodTipText()static double[]pairwiseCoupling(double[][] n, double[][] r)Implements pairwise coupling.java.lang.StringrandomWidthFactorTipText()voidsetLogLossDecoding(boolean newlogLossDecoding)Sets whether log loss decoding is used for random or exhaustive codes.voidsetMethod(SelectedTag newMethod)Sets the method used.voidsetOptions(java.lang.String[] options)Parses a given list of options.voidsetRandomWidthFactor(double newRandomWidthFactor)Sets the multiplier when generating random codes.voidsetUsePairwiseCoupling(boolean p)Set whether to use pairwise coupling with 1-vs-1 classification to improve probability estimates.java.lang.StringtoString()Prints the classifiers.java.lang.StringusePairwiseCouplingTipText()-
Methods inherited from class weka.classifiers.RandomizableSingleClassifierEnhancer
getSeed, seedTipText, setSeed
-
Methods inherited from class weka.classifiers.SingleClassifierEnhancer
classifierTipText, getClassifier, postExecution, preExecution, setClassifier
-
Methods inherited from class weka.classifiers.AbstractClassifier
batchSizeTipText, classifyInstance, debugTipText, distributionsForInstances, doNotCheckCapabilitiesTipText, forName, getBatchSize, getDebug, getDoNotCheckCapabilities, getNumDecimalPlaces, implementsMoreEfficientBatchPrediction, makeCopies, makeCopy, numDecimalPlacesTipText, run, runClassifier, setBatchSize, setDebug, setDoNotCheckCapabilities, setNumDecimalPlaces
-
-
-
-
Field Detail
-
METHOD_1_AGAINST_ALL
public static final int METHOD_1_AGAINST_ALL
1-against-all- See Also:
- Constant Field Values
-
METHOD_ERROR_RANDOM
public static final int METHOD_ERROR_RANDOM
random correction code- See Also:
- Constant Field Values
-
METHOD_ERROR_EXHAUSTIVE
public static final int METHOD_ERROR_EXHAUSTIVE
exhaustive correction code- See Also:
- Constant Field Values
-
METHOD_1_AGAINST_1
public static final int METHOD_1_AGAINST_1
1-against-1- See Also:
- Constant Field Values
-
TAGS_METHOD
public static final Tag[] TAGS_METHOD
The error correction modes
-
-
Method Detail
-
getCapabilities
public Capabilities getCapabilities()
Returns default capabilities of the classifier.- Specified by:
getCapabilitiesin interfaceCapabilitiesHandler- Specified by:
getCapabilitiesin interfaceClassifier- Overrides:
getCapabilitiesin classSingleClassifierEnhancer- Returns:
- the capabilities of this classifier
- See Also:
Capabilities
-
buildClassifier
public void buildClassifier(Instances insts) throws java.lang.Exception
Builds the classifiers.- Specified by:
buildClassifierin interfaceClassifier- Parameters:
insts- the training data.- Throws:
java.lang.Exception- if a classifier can't be built
-
individualPredictions
public double[] individualPredictions(Instance inst) throws java.lang.Exception
Returns the individual predictions of the base classifiers for an instance. Used by StackedMultiClassClassifier. Returns the probability for the second "class" predicted by each base classifier.- Parameters:
inst- the instance to get the prediction for- Returns:
- the individual predictions
- Throws:
java.lang.Exception- if the predictions can't be computed successfully
-
distributionForInstance
public double[] distributionForInstance(Instance inst) throws java.lang.Exception
Returns the distribution for an instance.- Specified by:
distributionForInstancein interfaceClassifier- Overrides:
distributionForInstancein classAbstractClassifier- Parameters:
inst- the instance to get the distribution for- Returns:
- the distribution
- Throws:
java.lang.Exception- if the distribution can't be computed successfully
-
toString
public java.lang.String toString()
Prints the classifiers.- Overrides:
toStringin classjava.lang.Object- Returns:
- a string representation of the classifier
-
listOptions
public java.util.Enumeration<Option> listOptions()
Returns an enumeration describing the available options- Specified by:
listOptionsin interfaceOptionHandler- Overrides:
listOptionsin classRandomizableSingleClassifierEnhancer- Returns:
- an enumeration of all the available options
-
setOptions
public void setOptions(java.lang.String[] options) throws java.lang.ExceptionParses a given list of options. Valid options are:-M <num> Sets the method to use. Valid values are 0 (1-against-all), 1 (random codes), 2 (exhaustive code), and 3 (1-against-1). (default 0)
-R <num> Sets the multiplier when using random codes. (default 2.0)
-P Use pairwise coupling (only has an effect for 1-against1)
-L Use log loss decoding for random and exhaustive codes.
-S <num> Random number seed. (default 1)
-D If set, classifier is run in debug mode and may output additional info to the console
-W Full name of base classifier. (default: weka.classifiers.functions.Logistic)
Options specific to classifier weka.classifiers.functions.Logistic:
-D Turn on debugging output.
-R <ridge> Set the ridge in the log-likelihood.
-M <number> Set the maximum number of iterations (default -1, until convergence).
- Specified by:
setOptionsin interfaceOptionHandler- Overrides:
setOptionsin classRandomizableSingleClassifierEnhancer- 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:
getOptionsin interfaceOptionHandler- Overrides:
getOptionsin classRandomizableSingleClassifierEnhancer- Returns:
- an array of strings suitable for passing to setOptions
-
globalInfo
public java.lang.String globalInfo()
- Returns:
- a description of the classifier suitable for displaying in the explorer/experimenter gui
-
logLossDecodingTipText
public java.lang.String logLossDecodingTipText()
- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
getLogLossDecoding
public boolean getLogLossDecoding()
Whether log loss decoding is used for random or exhaustive codes.- Returns:
- true if log loss is used
-
setLogLossDecoding
public void setLogLossDecoding(boolean newlogLossDecoding)
Sets whether log loss decoding is used for random or exhaustive codes.- Parameters:
newlogLossDecoding- true if log loss is to be used
-
randomWidthFactorTipText
public java.lang.String randomWidthFactorTipText()
- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
getRandomWidthFactor
public double getRandomWidthFactor()
Gets the multiplier when generating random codes. Will generate numClasses * m_RandomWidthFactor codes.- Returns:
- the width multiplier
-
setRandomWidthFactor
public void setRandomWidthFactor(double newRandomWidthFactor)
Sets the multiplier when generating random codes. Will generate numClasses * m_RandomWidthFactor codes.- Parameters:
newRandomWidthFactor- the new width multiplier
-
methodTipText
public java.lang.String methodTipText()
- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
getMethod
public SelectedTag getMethod()
Gets the method used. Will be one of METHOD_1_AGAINST_ALL, METHOD_ERROR_RANDOM, METHOD_ERROR_EXHAUSTIVE, or METHOD_1_AGAINST_1.- Returns:
- the current method.
-
setMethod
public void setMethod(SelectedTag newMethod)
Sets the method used. Will be one of METHOD_1_AGAINST_ALL, METHOD_ERROR_RANDOM, METHOD_ERROR_EXHAUSTIVE, or METHOD_1_AGAINST_1.- Parameters:
newMethod- the new method.
-
setUsePairwiseCoupling
public void setUsePairwiseCoupling(boolean p)
Set whether to use pairwise coupling with 1-vs-1 classification to improve probability estimates.- Parameters:
p- true if pairwise coupling is to be used
-
getUsePairwiseCoupling
public boolean getUsePairwiseCoupling()
Gets whether to use pairwise coupling with 1-vs-1 classification to improve probability estimates.- Returns:
- true if pairwise coupling is to be used
-
usePairwiseCouplingTipText
public java.lang.String usePairwiseCouplingTipText()
- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
pairwiseCoupling
public static double[] pairwiseCoupling(double[][] n, double[][] r)Implements pairwise coupling.- Parameters:
n- the sum of weights used to train each modelr- the probability estimate from each model- Returns:
- the coupled estimates
-
getRevision
public java.lang.String getRevision()
Returns the revision string.- Specified by:
getRevisionin interfaceRevisionHandler- Overrides:
getRevisionin classAbstractClassifier- Returns:
- the revision
-
main
public static void main(java.lang.String[] argv)
Main method for testing this class.- Parameters:
argv- the options
-
-