Class LibLINEAR

java.lang.Object
weka.classifiers.Classifier
weka.classifiers.functions.LibLINEAR
All Implemented Interfaces:
Serializable, 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:
  • Field Details

    • SVMTYPE_L2_LR

      public static final int SVMTYPE_L2_LR
      SVM solver type L2-regularized logistic regression
      See Also:
    • SVMTYPE_L2LOSS_SVM_DUAL

      public static final int SVMTYPE_L2LOSS_SVM_DUAL
      SVM solver type L2-loss support vector machines (dual)
      See Also:
    • SVMTYPE_L2LOSS_SVM

      public static final int SVMTYPE_L2LOSS_SVM
      SVM solver type L2-loss support vector machines (primal)
      See Also:
    • SVMTYPE_L1LOSS_SVM_DUAL

      public static final int SVMTYPE_L1LOSS_SVM_DUAL
      SVM solver type L1-loss support vector machines (dual)
      See Also:
    • SVMTYPE_MCSVM_CS

      public static final int SVMTYPE_MCSVM_CS
      SVM solver type multi-class support vector machines by Crammer and Singer
      See Also:
    • TAGS_SVMTYPE

      public static final Tag[] TAGS_SVMTYPE
      SVM solver types
  • Constructor Details

    • LibLINEAR

      public LibLINEAR()
  • Method Details

    • getModel

      public Object getModel()
    • globalInfo

      public 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:
      getTechnicalInformation in interface TechnicalInformationHandler
      Returns:
      the technical information about this class
    • listOptions

      public Enumeration listOptions()
      Returns an enumeration describing the available options.
      Specified by:
      listOptions in interface OptionHandler
      Overrides:
      listOptions in class Classifier
      Returns:
      an enumeration of all the available options.
    • setOptions

      public void setOptions(String[] options) throws Exception
      Sets 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:
      setOptions in interface OptionHandler
      Overrides:
      setOptions in class Classifier
      Parameters:
      options - the options to parse
      Throws:
      Exception - if parsing fails
    • getOptions

      public String[] getOptions()
      Returns the current options
      Specified by:
      getOptions in interface OptionHandler
      Overrides:
      getOptions in class Classifier
      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 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 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 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 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 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 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 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(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 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 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 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 Exception
      Computes the distribution for a given instance.
      Overrides:
      distributionForInstance in class Classifier
      Parameters:
      instance - the instance for which distribution is computed
      Returns:
      the distribution
      Throws:
      Exception - if the distribution can't be computed successfully
    • getCapabilities

      public Capabilities getCapabilities()
      Returns default capabilities of the classifier.
      Specified by:
      getCapabilities in interface CapabilitiesHandler
      Overrides:
      getCapabilities in class Classifier
      Returns:
      the capabilities of this classifier
      See Also:
    • buildClassifier

      public void buildClassifier(Instances insts) throws Exception
      builds the classifier
      Specified by:
      buildClassifier in class Classifier
      Parameters:
      insts - the training instances
      Throws:
      Exception - if liblinear classes not in classpath or liblinear encountered a problem
    • toString

      public String toString()
      returns a string representation
      Overrides:
      toString in class Object
      Returns:
      a string representation
    • getRevision

      public String getRevision()
      Returns the revision string.
      Specified by:
      getRevision in interface RevisionHandler
      Overrides:
      getRevision in class Classifier
      Returns:
      the revision
    • main

      public static void main(String[] args)
      Main method for testing this class.
      Parameters:
      args - the options