public class LibSVM
extends weka.classifiers.RandomizableClassifier
implements weka.core.TechnicalInformationHandler
BibTeX:
@misc{EL-Manzalawy2005, author = {Yasser EL-Manzalawy}, note = {You don't need to include the WLSVM package in the CLASSPATH}, title = {WLSVM}, year = {2005}, URL = {http://www.cs.iastate.edu/\~yasser/wlsvm/} } @misc{Chang2001, author = {Chih-Chung Chang and Chih-Jen Lin}, note = {The Weka classifier works with version 2.82 of LIBSVM}, title = {LIBSVM - A Library for Support Vector Machines}, year = {2001}, URL = {http://www.csie.ntu.edu.tw/\~cjlin/libsvm/} }Valid options are:
-S <int> Set type of SVM (default: 0) 0 = C-SVC 1 = nu-SVC 2 = one-class SVM 3 = epsilon-SVR 4 = nu-SVR
-K <int> Set type of kernel function (default: 2) 0 = linear: u'*v 1 = polynomial: (gamma*u'*v + coef0)^degree 2 = radial basis function: exp(-gamma*|u-v|^2) 3 = sigmoid: tanh(gamma*u'*v + coef0)
-D <int> Set degree in kernel function (default: 3)
-G <double> Set gamma in kernel function (default: 1/k)
-R <double> Set coef0 in kernel function (default: 0)
-C <double> Set the parameter C of C-SVC, epsilon-SVR, and nu-SVR (default: 1)
-N <double> Set the parameter nu of nu-SVC, one-class SVM, and nu-SVR (default: 0.5)
-Z Turns on normalization of input data (default: off)
-J Turn off nominal to binary conversion. WARNING: use only if your data is all numeric!
-V Turn off missing value replacement. WARNING: use only if your data has no missing values.
-P <double> Set the epsilon in loss function of epsilon-SVR (default: 0.1)
-M <double> Set cache memory size in MB (default: 40)
-E <double> Set tolerance of termination criterion (default: 0.001)
-H Turns the shrinking heuristics off (default: on)
-W <double> Set the parameters C of class i to weight[i]*C, for C-SVC. E.g., for a 3-class problem, you could use "1 1 1" for equally weighted classes. (default: 1 for all classes)
-B Trains a SVC model instead of a SVR one (default: SVR)
-model <file> Specifies the filename to save the libsvm-internal model to. Gets ignored if a directory is provided.
-D If set, classifier is run in debug mode and may output additional info to the console
-seed <num> Seed for the random number generator when -B is used. (default = 1)
LibSVMLoader
,
LibSVMSaver
,
Serialized FormModifier and Type | Field and Description |
---|---|
static int |
KERNELTYPE_LINEAR
kernel type linear: u'*v.
|
static int |
KERNELTYPE_POLYNOMIAL
kernel type polynomial: (gamma*u'*v + coef0)^degree.
|
static int |
KERNELTYPE_RBF
kernel type radial basis function: exp(-gamma*|u-v|^2).
|
static int |
KERNELTYPE_SIGMOID
kernel type sigmoid: tanh(gamma*u'*v + coef0).
|
static int |
SVMTYPE_C_SVC
SVM type C-SVC (classification).
|
static int |
SVMTYPE_EPSILON_SVR
SVM type epsilon-SVR (regression).
|
static int |
SVMTYPE_NU_SVC
SVM type nu-SVC (classification).
|
static int |
SVMTYPE_NU_SVR
SVM type nu-SVR (regression).
|
static int |
SVMTYPE_ONE_CLASS_SVM
SVM type one-class SVM (classification).
|
static weka.core.Tag[] |
TAGS_KERNELTYPE
the different kernel types.
|
static weka.core.Tag[] |
TAGS_SVMTYPE
SVM types.
|
Constructor and Description |
---|
LibSVM() |
Modifier and Type | Method and Description |
---|---|
void |
buildClassifier(weka.core.Instances insts)
builds the classifier.
|
java.lang.String |
cacheSizeTipText()
Returns the tip text for this property.
|
java.lang.String |
coef0TipText()
Returns the tip text for this property.
|
java.lang.String |
costTipText()
Returns the tip text for this property.
|
java.lang.String |
degreeTipText()
Returns the tip text for this property.
|
double[] |
distributionForInstance(weka.core.Instance instance)
Computes the distribution for a given instance.
|
java.lang.String |
doNotReplaceMissingValuesTipText()
Returns the tip text for this property.
|
java.lang.String |
epsTipText()
Returns the tip text for this property.
|
java.lang.String |
gammaTipText()
Returns the tip text for this property.
|
double |
getCacheSize()
Gets cache memory size in MB.
|
weka.core.Capabilities |
getCapabilities()
Returns default capabilities of the classifier.
|
double |
getCoef0()
Gets coef.
|
double |
getCost()
Sets the parameter C of C-SVC, epsilon-SVR, and nu-SVR.
|
int |
getDegree()
Gets the degree of the kernel.
|
boolean |
getDoNotReplaceMissingValues()
Gets whether automatic replacement of missing values is
disabled.
|
double |
getEps()
Gets tolerance of termination criterion.
|
double |
getGamma()
Gets gamma.
|
weka.core.SelectedTag |
getKernelType()
Gets type of kernel function.
|
double |
getLoss()
Gets the epsilon in loss function of epsilon-SVR.
|
java.io.File |
getModelFile()
Returns the file to save the libsvm-internal model to.
|
boolean |
getNormalize()
whether to normalize input data.
|
double |
getNu()
Gets nu of nu-SVC, one-class SVM, and nu-SVR (default 0.5).
|
java.lang.String[] |
getOptions()
Returns the current options.
|
boolean |
getProbabilityEstimates()
Returns whether to generate probability estimates instead of -1/+1 for
classification problems.
|
java.lang.String |
getRevision()
Returns the revision string.
|
boolean |
getShrinking()
whether to use the shrinking heuristics.
|
weka.core.SelectedTag |
getSVMType()
Gets type of SVM.
|
weka.core.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.
|
java.lang.String |
getWeights()
Gets the parameters C of class i to weight[i]*C, for C-SVC (default 1).
|
java.lang.String |
globalInfo()
Returns a string describing classifier.
|
java.lang.String |
kernelTypeTipText()
Returns the tip text for this property.
|
java.util.Enumeration |
listOptions()
Returns an enumeration describing the available options.
|
java.lang.String |
lossTipText()
Returns the tip text for this property.
|
static void |
main(java.lang.String[] args)
Main method for testing this class.
|
java.lang.String |
modelFileTipText()
Returns the tip text for this property.
|
java.lang.String |
normalizeTipText()
Returns the tip text for this property.
|
java.lang.String |
nuTipText()
Returns the tip text for this property.
|
java.lang.String |
probabilityEstimatesTipText()
Returns the tip text for this property.
|
void |
setCacheSize(double value)
Sets cache memory size in MB (default 40).
|
void |
setCoef0(double value)
Sets coef (default 0).
|
void |
setCost(double value)
Sets the parameter C of C-SVC, epsilon-SVR, and nu-SVR (default 1).
|
void |
setDegree(int value)
Sets the degree of the kernel.
|
void |
setDoNotReplaceMissingValues(boolean b)
Whether to turn off automatic replacement of missing values.
|
void |
setEps(double value)
Sets tolerance of termination criterion (default 0.001).
|
void |
setGamma(double value)
Sets gamma (default = 1/no of attributes).
|
void |
setKernelType(weka.core.SelectedTag value)
Sets type of kernel function (default KERNELTYPE_RBF).
|
void |
setLoss(double value)
Sets the epsilon in loss function of epsilon-SVR (default 0.1).
|
void |
setModelFile(java.io.File value)
Sets the file to save the libsvm-internal model to.
|
void |
setNormalize(boolean value)
whether to normalize input data.
|
void |
setNu(double value)
Sets nu of nu-SVC, one-class SVM, and nu-SVR (default 0.5).
|
void |
setOptions(java.lang.String[] options)
Sets the classifier options
Valid options are:
|
void |
setProbabilityEstimates(boolean value)
Sets whether probability estimates are generated instead of -1/+1 for
classification problems.
|
void |
setShrinking(boolean value)
whether to use the shrinking heuristics.
|
void |
setSVMType(weka.core.SelectedTag value)
Sets type of SVM (default SVMTYPE_C_SVC).
|
void |
setWeights(java.lang.String weightsStr)
Sets the parameters C of class i to weight[i]*C, for C-SVC (default 1).
|
java.lang.String |
shrinkingTipText()
Returns the tip text for this property.
|
java.lang.String |
SVMTypeTipText()
Returns the tip text for this property.
|
java.lang.String |
toString()
returns a string representation.
|
java.lang.String |
weightsTipText()
Returns the tip text for this property.
|
batchSizeTipText, classifyInstance, debugTipText, distributionsForInstances, doNotCheckCapabilitiesTipText, forName, getBatchSize, getDebug, getDoNotCheckCapabilities, getNumDecimalPlaces, implementsMoreEfficientBatchPrediction, makeCopies, makeCopy, numDecimalPlacesTipText, postExecution, preExecution, run, runClassifier, setBatchSize, setDebug, setDoNotCheckCapabilities, setNumDecimalPlaces
public static final int SVMTYPE_C_SVC
public static final int SVMTYPE_NU_SVC
public static final int SVMTYPE_ONE_CLASS_SVM
public static final int SVMTYPE_EPSILON_SVR
public static final int SVMTYPE_NU_SVR
public static final weka.core.Tag[] TAGS_SVMTYPE
public static final int KERNELTYPE_LINEAR
public static final int KERNELTYPE_POLYNOMIAL
public static final int KERNELTYPE_RBF
public static final int KERNELTYPE_SIGMOID
public static final weka.core.Tag[] TAGS_KERNELTYPE
public java.lang.String globalInfo()
public weka.core.TechnicalInformation getTechnicalInformation()
getTechnicalInformation
in interface weka.core.TechnicalInformationHandler
public java.util.Enumeration listOptions()
listOptions
in interface weka.core.OptionHandler
listOptions
in class weka.classifiers.RandomizableClassifier
public void setOptions(java.lang.String[] options) throws java.lang.Exception
-S <int> Set type of SVM (default: 0) 0 = C-SVC 1 = nu-SVC 2 = one-class SVM 3 = epsilon-SVR 4 = nu-SVR
-K <int> Set type of kernel function (default: 2) 0 = linear: u'*v 1 = polynomial: (gamma*u'*v + coef0)^degree 2 = radial basis function: exp(-gamma*|u-v|^2) 3 = sigmoid: tanh(gamma*u'*v + coef0)
-D <int> Set degree in kernel function (default: 3)
-G <double> Set gamma in kernel function (default: 1/k)
-R <double> Set coef0 in kernel function (default: 0)
-C <double> Set the parameter C of C-SVC, epsilon-SVR, and nu-SVR (default: 1)
-N <double> Set the parameter nu of nu-SVC, one-class SVM, and nu-SVR (default: 0.5)
-Z Turns on normalization of input data (default: off)
-J Turn off nominal to binary conversion. WARNING: use only if your data is all numeric!
-V Turn off missing value replacement. WARNING: use only if your data has no missing values.
-P <double> Set the epsilon in loss function of epsilon-SVR (default: 0.1)
-M <double> Set cache memory size in MB (default: 40)
-E <double> Set tolerance of termination criterion (default: 0.001)
-H Turns the shrinking heuristics off (default: on)
-W <double> Set the parameters C of class i to weight[i]*C, for C-SVC. E.g., for a 3-class problem, you could use "1 1 1" for equally weighted classes. (default: 1 for all classes)
-B Trains a SVC model instead of a SVR one (default: SVR)
-model <file> Specifies the filename to save the libsvm-internal model to. Gets ignored if a directory is provided.
-D If set, classifier is run in debug mode and may output additional info to the console
-seed <num> Seed for the random number generator when -B is used. (default = 1)
setOptions
in interface weka.core.OptionHandler
setOptions
in class weka.classifiers.RandomizableClassifier
options
- the options to parsejava.lang.Exception
- if parsing failspublic java.lang.String[] getOptions()
getOptions
in interface weka.core.OptionHandler
getOptions
in class weka.classifiers.RandomizableClassifier
public void setSVMType(weka.core.SelectedTag value)
value
- the type of the SVMpublic weka.core.SelectedTag getSVMType()
public java.lang.String SVMTypeTipText()
public void setKernelType(weka.core.SelectedTag value)
value
- the kernel typepublic weka.core.SelectedTag getKernelType()
public java.lang.String kernelTypeTipText()
public void setDegree(int value)
value
- the degree of the kernelpublic int getDegree()
public java.lang.String degreeTipText()
public void setGamma(double value)
value
- the gamma valuepublic double getGamma()
public java.lang.String gammaTipText()
public void setCoef0(double value)
value
- the coefpublic double getCoef0()
public java.lang.String coef0TipText()
public void setNu(double value)
value
- the new nu valuepublic double getNu()
public java.lang.String nuTipText()
public void setCacheSize(double value)
value
- the memory size in MBpublic double getCacheSize()
public java.lang.String cacheSizeTipText()
public void setCost(double value)
value
- the cost valuepublic double getCost()
public java.lang.String costTipText()
public void setEps(double value)
value
- the tolerancepublic double getEps()
public java.lang.String epsTipText()
public void setLoss(double value)
value
- the loss epsilonpublic double getLoss()
public java.lang.String lossTipText()
public void setShrinking(boolean value)
value
- true uses shrinkingpublic boolean getShrinking()
public java.lang.String shrinkingTipText()
public void setNormalize(boolean value)
value
- whether to normalize the datapublic boolean getNormalize()
public java.lang.String normalizeTipText()
public java.lang.String doNotReplaceMissingValuesTipText()
public void setDoNotReplaceMissingValues(boolean b)
b
- true if automatic missing values replacement is
to be disabled.public boolean getDoNotReplaceMissingValues()
public void setWeights(java.lang.String weightsStr)
weightsStr
- the weights (doubles, separated by blanks)public java.lang.String getWeights()
public java.lang.String weightsTipText()
public void setProbabilityEstimates(boolean value)
value
- whether to predict probabilitiespublic boolean getProbabilityEstimates()
public java.lang.String probabilityEstimatesTipText()
public void setModelFile(java.io.File value)
value
- the filename/directorypublic java.io.File getModelFile()
public java.lang.String modelFileTipText()
public double[] distributionForInstance(weka.core.Instance instance) throws java.lang.Exception
distributionForInstance
in interface weka.classifiers.Classifier
distributionForInstance
in class weka.classifiers.AbstractClassifier
instance
- the instance for which distribution is computedjava.lang.Exception
- if the distribution can't be computed successfullypublic weka.core.Capabilities getCapabilities()
getCapabilities
in interface weka.classifiers.Classifier
getCapabilities
in interface weka.core.CapabilitiesHandler
getCapabilities
in class weka.classifiers.AbstractClassifier
public void buildClassifier(weka.core.Instances insts) throws java.lang.Exception
buildClassifier
in interface weka.classifiers.Classifier
insts
- the training instancesjava.lang.Exception
- if libsvm encountered a problempublic java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String getRevision()
getRevision
in interface weka.core.RevisionHandler
getRevision
in class weka.classifiers.AbstractClassifier
public static void main(java.lang.String[] args)
args
- the options