Package weka.classifiers.functions
Class LibLINEAR
- java.lang.Object
-
- weka.classifiers.Classifier
-
- weka.classifiers.functions.LibLINEAR
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable,CapabilitiesHandler,OptionHandler,RevisionHandler,TechnicalInformationHandler
public class LibLINEAR extends Classifier implements TechnicalInformationHandler
A wrapper class for the liblinear tools (the liblinear classes, typically the jar file, need to be in the classpath to use this classifier).
Rong-En Fan, Kai-Wei Chang, Cho-Jui Hsieh, Xiang-Rui Wang, Chih-Jen Lin (2008). LIBLINEAR - A Library for Large Linear Classification. URL http://www.csie.ntu.edu.tw/~cjlin/liblinear/. BibTeX:@misc{Fan2008, author = {Rong-En Fan and Kai-Wei Chang and Cho-Jui Hsieh and Xiang-Rui Wang and Chih-Jen Lin}, note = {The Weka classifier works with version 1.33 of LIBLINEAR}, title = {LIBLINEAR - A Library for Large Linear Classification}, year = {2008}, URL = {http://www.csie.ntu.edu.tw/\~cjlin/liblinear/} }Valid options are:-S <int> Set type of solver (default: 1) 0 = L2-regularized logistic regression 1 = L2-loss support vector machines (dual) 2 = L2-loss support vector machines (primal) 3 = L1-loss support vector machines (dual) 4 = multi-class support vector machines by Crammer and Singer-C <double> Set the cost parameter C (default: 1)
-Z Turn on normalization of input data (default: off)
-N Turn on nominal to binary conversion.
-M Turn off missing value replacement. WARNING: use only if your data has no missing values.
-P Use probability estimation (default: off) currently for L2-regularized logistic regression only!
-E <double> Set tolerance of termination criterion (default: 0.01)
-W <double> Set the parameters C of class i to weight[i]*C (default: 1)
-B <double> Add Bias term with the given value if >= 0; if < 0, no bias term added (default: 1)
-D If set, classifier is run in debug mode and may output additional info to the console
- Version:
- $Revision: 5917 $
- Author:
- Benedikt Waldvogel (mail at bwaldvogel.de)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static intSVMTYPE_L1LOSS_SVM_DUALSVM solver type L1-loss support vector machines (dual)static intSVMTYPE_L2_LRSVM solver type L2-regularized logistic regressionstatic intSVMTYPE_L2LOSS_SVMSVM solver type L2-loss support vector machines (primal)static intSVMTYPE_L2LOSS_SVM_DUALSVM solver type L2-loss support vector machines (dual)static intSVMTYPE_MCSVM_CSSVM solver type multi-class support vector machines by Crammer and Singerstatic Tag[]TAGS_SVMTYPESVM solver types
-
Constructor Summary
Constructors Constructor Description LibLINEAR()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringbiasTipText()Returns the tip text for this propertyvoidbuildClassifier(Instances insts)builds the classifierjava.lang.StringconvertNominalToBinaryTipText()Returns the tip text for this propertyjava.lang.StringcostTipText()Returns the tip text for this propertydouble[]distributionForInstance(Instance instance)Computes the distribution for a given instance.java.lang.StringdoNotReplaceMissingValuesTipText()Returns the tip text for this propertyjava.lang.StringepsTipText()Returns the tip text for this propertydoublegetBias()Returns bias term value (default 1) No bias term is added if value < 0CapabilitiesgetCapabilities()Returns default capabilities of the classifier.booleangetConvertNominalToBinary()Gets whether conversion of nominal to binary is turned on.doublegetCost()Returns the cost parameter CbooleangetDoNotReplaceMissingValues()Gets whether automatic replacement of missing values is disabled.doublegetEps()Gets tolerance of termination criterionjava.lang.ObjectgetModel()booleangetNormalize()whether to normalize input datajava.lang.String[]getOptions()Returns the current optionsbooleangetProbabilityEstimates()Sets whether to generate probability estimates instead of -1/+1 for classification problems.java.lang.StringgetRevision()Returns the revision string.SelectedTaggetSVMType()Gets type of SVMTechnicalInformationgetTechnicalInformation()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.java.lang.StringgetWeights()Gets the parameters C of class i to weight[i]*C (default 1).java.lang.StringglobalInfo()Returns a string describing classifierstatic booleanisPresent()returns whether the liblinear classes are present or not, i.e.java.util.EnumerationlistOptions()Returns an enumeration describing the available options.static voidmain(java.lang.String[] args)Main method for testing this class.java.lang.StringnormalizeTipText()Returns the tip text for this propertyjava.lang.StringprobabilityEstimatesTipText()Returns the tip text for this propertyvoidsetBias(double value)Sets bias term value (default 1) No bias term is added if value < 0voidsetConvertNominalToBinary(boolean b)Whether to turn on conversion of nominal attributes to binary.voidsetCost(double value)Sets the cost parameter C (default 1)voidsetDoNotReplaceMissingValues(boolean b)Whether to turn off automatic replacement of missing values.voidsetEps(double value)Sets tolerance of termination criterion (default 0.001)voidsetNormalize(boolean value)whether to normalize input datavoidsetOptions(java.lang.String[] options)Sets the classifier optionsvoidsetProbabilityEstimates(boolean value)Returns whether probability estimates are generated instead of -1/+1 for classification problems.voidsetSVMType(SelectedTag value)Sets type of SVM (default SVMTYPE_L2)voidsetWeights(java.lang.String weightsStr)Sets the parameters C of class i to weight[i]*C (default 1).java.lang.StringSVMTypeTipText()Returns the tip text for this propertyjava.lang.StringtoString()returns a string representationjava.lang.StringweightsTipText()Returns the tip text for this property-
Methods inherited from class weka.classifiers.Classifier
classifyInstance, debugTipText, forName, getDebug, makeCopies, makeCopy, setDebug
-
-
-
-
Field Detail
-
SVMTYPE_L2_LR
public static final int SVMTYPE_L2_LR
SVM solver type L2-regularized logistic regression- See Also:
- Constant Field Values
-
SVMTYPE_L2LOSS_SVM_DUAL
public static final int SVMTYPE_L2LOSS_SVM_DUAL
SVM solver type L2-loss support vector machines (dual)- See Also:
- Constant Field Values
-
SVMTYPE_L2LOSS_SVM
public static final int SVMTYPE_L2LOSS_SVM
SVM solver type L2-loss support vector machines (primal)- See Also:
- Constant Field Values
-
SVMTYPE_L1LOSS_SVM_DUAL
public static final int SVMTYPE_L1LOSS_SVM_DUAL
SVM solver type L1-loss support vector machines (dual)- See Also:
- Constant Field Values
-
SVMTYPE_MCSVM_CS
public static final int SVMTYPE_MCSVM_CS
SVM solver type multi-class support vector machines by Crammer and Singer- See Also:
- Constant Field Values
-
TAGS_SVMTYPE
public static final Tag[] TAGS_SVMTYPE
SVM solver types
-
-
Method Detail
-
getModel
public java.lang.Object getModel()
-
globalInfo
public java.lang.String globalInfo()
Returns a string describing classifier- Returns:
- a description suitable for displaying in the explorer/experimenter gui
-
getTechnicalInformation
public TechnicalInformation 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:
getTechnicalInformationin interfaceTechnicalInformationHandler- Returns:
- the technical information about this class
-
listOptions
public java.util.Enumeration listOptions()
Returns an enumeration describing the available options.- Specified by:
listOptionsin interfaceOptionHandler- Overrides:
listOptionsin classClassifier- Returns:
- an enumeration of all the available options.
-
setOptions
public void setOptions(java.lang.String[] options) throws java.lang.ExceptionSets the classifier options Valid options are:-S <int> Set type of solver (default: 1) 0 = L2-regularized logistic regression 1 = L2-loss support vector machines (dual) 2 = L2-loss support vector machines (primal) 3 = L1-loss support vector machines (dual) 4 = multi-class support vector machines by Crammer and Singer-C <double> Set the cost parameter C (default: 1)
-Z Turn on normalization of input data (default: off)
-N Turn on nominal to binary conversion.
-M Turn off missing value replacement. WARNING: use only if your data has no missing values.
-P Use probability estimation (default: off) currently for L2-regularized logistic regression only!
-E <double> Set tolerance of termination criterion (default: 0.01)
-W <double> Set the parameters C of class i to weight[i]*C (default: 1)
-B <double> Add Bias term with the given value if >= 0; if < 0, no bias term added (default: 1)
-D If set, classifier is run in debug mode and may output additional info to the console
- Specified by:
setOptionsin interfaceOptionHandler- Overrides:
setOptionsin classClassifier- Parameters:
options- the options to parse- Throws:
java.lang.Exception- if parsing fails
-
getOptions
public java.lang.String[] getOptions()
Returns the current options- Specified by:
getOptionsin interfaceOptionHandler- Overrides:
getOptionsin classClassifier- Returns:
- the current setup
-
isPresent
public static boolean isPresent()
returns whether the liblinear classes are present or not, i.e. whether the classes are in the classpath or not- Returns:
- whether the liblinear classes are available
-
setSVMType
public void setSVMType(SelectedTag value)
Sets type of SVM (default SVMTYPE_L2)- Parameters:
value- the type of the SVM
-
getSVMType
public SelectedTag getSVMType()
Gets type of SVM- Returns:
- the type of the SVM
-
SVMTypeTipText
public java.lang.String SVMTypeTipText()
Returns the tip text for this property- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
setCost
public void setCost(double value)
Sets the cost parameter C (default 1)- Parameters:
value- the cost value
-
getCost
public double getCost()
Returns the cost parameter C- Returns:
- the cost value
-
costTipText
public java.lang.String costTipText()
Returns the tip text for this property- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
setEps
public void setEps(double value)
Sets tolerance of termination criterion (default 0.001)- Parameters:
value- the tolerance
-
getEps
public double getEps()
Gets tolerance of termination criterion- Returns:
- the current tolerance
-
epsTipText
public java.lang.String epsTipText()
Returns the tip text for this property- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
setBias
public void setBias(double value)
Sets bias term value (default 1) No bias term is added if value < 0- Parameters:
value- the bias term value
-
getBias
public double getBias()
Returns bias term value (default 1) No bias term is added if value < 0- Returns:
- the bias term value
-
biasTipText
public java.lang.String biasTipText()
Returns the tip text for this property- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
normalizeTipText
public java.lang.String normalizeTipText()
Returns the tip text for this property- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
setNormalize
public void setNormalize(boolean value)
whether to normalize input data- Parameters:
value- whether to normalize the data
-
getNormalize
public boolean getNormalize()
whether to normalize input data- Returns:
- true, if the data is normalized
-
convertNominalToBinaryTipText
public java.lang.String convertNominalToBinaryTipText()
Returns the tip text for this property- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
setConvertNominalToBinary
public void setConvertNominalToBinary(boolean b)
Whether to turn on conversion of nominal attributes to binary.- Parameters:
b- true if nominal to binary conversion is to be turned on
-
getConvertNominalToBinary
public boolean getConvertNominalToBinary()
Gets whether conversion of nominal to binary is turned on.- Returns:
- true if nominal to binary conversion is turned on.
-
doNotReplaceMissingValuesTipText
public java.lang.String doNotReplaceMissingValuesTipText()
Returns the tip text for this property- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
setDoNotReplaceMissingValues
public void setDoNotReplaceMissingValues(boolean b)
Whether to turn off automatic replacement of missing values. Set to true only if the data does not contain missing values.- Parameters:
b- true if automatic missing values replacement is to be disabled.
-
getDoNotReplaceMissingValues
public boolean getDoNotReplaceMissingValues()
Gets whether automatic replacement of missing values is disabled.- Returns:
- true if automatic replacement of missing values is disabled.
-
setWeights
public void setWeights(java.lang.String weightsStr)
Sets the parameters C of class i to weight[i]*C (default 1). Blank separated list of doubles.- Parameters:
weightsStr- the weights (doubles, separated by blanks)
-
getWeights
public java.lang.String getWeights()
Gets the parameters C of class i to weight[i]*C (default 1). Blank separated doubles.- Returns:
- the weights (doubles separated by blanks)
-
weightsTipText
public java.lang.String weightsTipText()
Returns the tip text for this property- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
setProbabilityEstimates
public void setProbabilityEstimates(boolean value)
Returns whether probability estimates are generated instead of -1/+1 for classification problems.- Parameters:
value- whether to predict probabilities
-
getProbabilityEstimates
public boolean getProbabilityEstimates()
Sets whether to generate probability estimates instead of -1/+1 for classification problems.- Returns:
- true, if probability estimates should be returned
-
probabilityEstimatesTipText
public java.lang.String probabilityEstimatesTipText()
Returns the tip text for this property- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
distributionForInstance
public double[] distributionForInstance(Instance instance) throws java.lang.Exception
Computes the distribution for a given instance.- Overrides:
distributionForInstancein classClassifier- Parameters:
instance- the instance for which distribution is computed- Returns:
- the distribution
- Throws:
java.lang.Exception- if the distribution can't be computed successfully
-
getCapabilities
public Capabilities getCapabilities()
Returns default capabilities of the classifier.- Specified by:
getCapabilitiesin interfaceCapabilitiesHandler- Overrides:
getCapabilitiesin classClassifier- Returns:
- the capabilities of this classifier
- See Also:
Capabilities
-
buildClassifier
public void buildClassifier(Instances insts) throws java.lang.Exception
builds the classifier- Specified by:
buildClassifierin classClassifier- Parameters:
insts- the training instances- Throws:
java.lang.Exception- if liblinear classes not in classpath or liblinear encountered a problem
-
toString
public java.lang.String toString()
returns a string representation- Overrides:
toStringin classjava.lang.Object- Returns:
- a string representation
-
getRevision
public java.lang.String getRevision()
Returns the revision string.- Specified by:
getRevisionin interfaceRevisionHandler- Overrides:
getRevisionin classClassifier- Returns:
- the revision
-
main
public static void main(java.lang.String[] args)
Main method for testing this class.- Parameters:
args- the options
-
-