edu.cmu.minorthird.classify.algorithms.svm
Class SVMLearner

java.lang.Object
  extended by edu.cmu.minorthird.classify.BatchClassifierLearner
      extended by edu.cmu.minorthird.classify.algorithms.svm.SVMLearner
All Implemented Interfaces:
ClassifierLearner, java.lang.Cloneable
Direct Known Subclasses:
Recommended.SVMLearner

public class SVMLearner
extends BatchClassifierLearner

Wraps the svm.svm_train algorithm from libsvm (http://www.csie.ntu.edu.tw/~cjlin/libsvm/)

Parameterization is done via an SVM object (see libsvm docs for examples/info).

There are a few setParameterXXX methods to do some changes. Use these after calling new SVMLearner() and before starting training.

Author:
ksteppe, Frank Lin

Field Summary
static java.lang.String cacheSizeHelp
           
static java.lang.String coef0Help
           
static java.lang.String cParameterHelp
           
static java.lang.String cParameterWeightHelp
           
static java.lang.String degreeHelp
           
static java.lang.String doProbabilityEstimatesHelp
           
static java.lang.String gammaHelp
           
static java.lang.String kernelTypeHelp
           
static java.lang.String lossFunctionEpsilonHelp
           
static java.lang.String nuHelp
           
static java.lang.String parameterSVMTypeHelp
           
static java.lang.String stoppingCriteriaHelp
           
static java.lang.String useShrinkingHeuristicsHelp
           
 
Fields inherited from class edu.cmu.minorthird.classify.BatchClassifierLearner
classifier, dataset
 
Constructor Summary
SVMLearner()
          default constructor
SVMLearner(libsvm.svm_parameter parameters)
          Construct learner using given params
 
Method Summary
 Classifier batchTrain(Dataset dataset)
          Train a classifier using the given dataset.
 double getCacheSize()
           
 java.lang.String getCacheSizeHelp()
           
 double getCoef0()
           
 java.lang.String getCoef0Help()
           
 double getCParameter()
           
 java.lang.String getCParameterHelp()
           
 int getCParameterWeight()
           
 java.lang.String getCParameterWeightHelp()
           
protected static libsvm.svm_parameter getDefaultParameters()
          sets the default parameters for the svm

use the setParameterXXX methods to adjust them

 int getDegree()
           
 java.lang.String getDegreeHelp()
           
 boolean getDoProbabilityEstimates()
           
 java.lang.String getDoProbabilityEstimatesHelp()
           
 double getGamma()
           
 java.lang.String getGammaHelp()
           
 int getKernelType()
           
 java.lang.String getKernelTypeHelp()
           
 double getLossFunctionEpsilon()
           
 java.lang.String getLossFunctionEpsilonHelp()
           
 double getNu()
           
 java.lang.String getNuHelp()
           
 int getParameterSVMType()
           
 java.lang.String getParameterSVMTypeHelp()
           
 ExampleSchema getSchema()
          Returns the ExampleSchema - constraints on what the Examples will be.
 double getStoppingCriteria()
           
 java.lang.String getStoppingCriteriaHelp()
           
 boolean getUseShrinkingHeuristics()
           
 java.lang.String getUseShrinkingHeuristicsHelp()
           
 void setCacheSize(double s)
           
 void setCoef0(double c)
           
 void setCParameter(double c)
           
 void setCParameterWeight(int w)
           
 void setDegree(int deg)
           
 void setDoProbabilityEstimates(boolean flag)
          Tell the learner to train a classifier capable of computing probability estimates for each class.
 void setGamma(double g)
           
 void setKernelType(int type)
           
 void setLossFunctionEpsilon(double l)
           
 void setNu(double n)
           
 void setParameterC(double c)
           
 void setParameterGamma(double gamma)
          The default for Gamma is 0, which works for a linear kernel, but not for other types of kernels
 void setParameterKernelType(int type)
          Default kernel type is linear
 void setParameterSVMType(int type)
           
 void setSchema(ExampleSchema schema)
          Accept an ExampleSchema - constraints on what the Examples will be.
 void setStoppingCriteria(double c)
           
 void setUseShrinkingHeuristics(boolean flag)
           
 
Methods inherited from class edu.cmu.minorthird.classify.BatchClassifierLearner
addExample, completeTraining, copy, getClassifier, hasNextQuery, nextQuery, reset, setInstancePool
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

parameterSVMTypeHelp

public static java.lang.String parameterSVMTypeHelp

kernelTypeHelp

public static java.lang.String kernelTypeHelp

degreeHelp

public static java.lang.String degreeHelp

gammaHelp

public static java.lang.String gammaHelp

coef0Help

public static java.lang.String coef0Help

nuHelp

public static java.lang.String nuHelp

cacheSizeHelp

public static java.lang.String cacheSizeHelp

cParameterHelp

public static java.lang.String cParameterHelp

stoppingCriteriaHelp

public static java.lang.String stoppingCriteriaHelp

lossFunctionEpsilonHelp

public static java.lang.String lossFunctionEpsilonHelp

useShrinkingHeuristicsHelp

public static java.lang.String useShrinkingHeuristicsHelp

cParameterWeightHelp

public static java.lang.String cParameterWeightHelp

doProbabilityEstimatesHelp

public static java.lang.String doProbabilityEstimatesHelp
Constructor Detail

SVMLearner

public SVMLearner(libsvm.svm_parameter parameters)
Construct learner using given params

Parameters:
parameters - parameters to the SVM

SVMLearner

public SVMLearner()
default constructor

Method Detail

getDefaultParameters

protected static libsvm.svm_parameter getDefaultParameters()
sets the default parameters for the svm

use the setParameterXXX methods to adjust them


setSchema

public void setSchema(ExampleSchema schema)
Description copied from interface: ClassifierLearner
Accept an ExampleSchema - constraints on what the Examples will be.


getSchema

public ExampleSchema getSchema()
Description copied from interface: ClassifierLearner
Returns the ExampleSchema - constraints on what the Examples will be.


batchTrain

public Classifier batchTrain(Dataset dataset)
Train a classifier using the given dataset. An svm_problem object is created from the dataset. A svm_model is generated by the svm library. That model is held by the returned Classifier.

Specified by:
batchTrain in class BatchClassifierLearner
Parameters:
dataset - Dataset representing all usable training data
Returns:
a SVMClassifier object which wraps the libsvm prediction code

setParameterSVMType

public void setParameterSVMType(int type)

getParameterSVMType

public int getParameterSVMType()

getParameterSVMTypeHelp

public java.lang.String getParameterSVMTypeHelp()

setKernelType

public void setKernelType(int type)

getKernelType

public int getKernelType()

getKernelTypeHelp

public java.lang.String getKernelTypeHelp()

setDegree

public void setDegree(int deg)

getDegree

public int getDegree()

getDegreeHelp

public java.lang.String getDegreeHelp()

setGamma

public void setGamma(double g)

getGamma

public double getGamma()

getGammaHelp

public java.lang.String getGammaHelp()

setCoef0

public void setCoef0(double c)

getCoef0

public double getCoef0()

getCoef0Help

public java.lang.String getCoef0Help()

setNu

public void setNu(double n)

getNu

public double getNu()

getNuHelp

public java.lang.String getNuHelp()

setCacheSize

public void setCacheSize(double s)

getCacheSize

public double getCacheSize()

getCacheSizeHelp

public java.lang.String getCacheSizeHelp()

setCParameter

public void setCParameter(double c)

getCParameter

public double getCParameter()

getCParameterHelp

public java.lang.String getCParameterHelp()

setStoppingCriteria

public void setStoppingCriteria(double c)

getStoppingCriteria

public double getStoppingCriteria()

getStoppingCriteriaHelp

public java.lang.String getStoppingCriteriaHelp()

setLossFunctionEpsilon

public void setLossFunctionEpsilon(double l)

getLossFunctionEpsilon

public double getLossFunctionEpsilon()

getLossFunctionEpsilonHelp

public java.lang.String getLossFunctionEpsilonHelp()

setUseShrinkingHeuristics

public void setUseShrinkingHeuristics(boolean flag)

getUseShrinkingHeuristics

public boolean getUseShrinkingHeuristics()

getUseShrinkingHeuristicsHelp

public java.lang.String getUseShrinkingHeuristicsHelp()

setCParameterWeight

public void setCParameterWeight(int w)

getCParameterWeight

public int getCParameterWeight()

getCParameterWeightHelp

public java.lang.String getCParameterWeightHelp()

setDoProbabilityEstimates

public void setDoProbabilityEstimates(boolean flag)
Tell the learner to train a classifier capable of computing probability estimates for each class. Default to False. Turning this option on will cause the training to take a longer time.

Parameters:
flag - Boolean value telling the learner whether or not to compute probability estimates

getDoProbabilityEstimates

public boolean getDoProbabilityEstimates()

getDoProbabilityEstimatesHelp

public java.lang.String getDoProbabilityEstimatesHelp()

setParameterKernelType

public void setParameterKernelType(int type)
Default kernel type is linear

Parameters:
type - integer from the svm_parameter class

setParameterGamma

public void setParameterGamma(double gamma)
The default for Gamma is 0, which works for a linear kernel, but not for other types of kernels

Parameters:
gamma - double to be used as the gamma parameter. Default is 0

setParameterC

public void setParameterC(double c)
Parameters:
c - double to be used as the C parameter. Default is 1