ModErn Text Analysis
META Enumerates Textual Applications
Public Types | Public Member Functions | Static Public Attributes | Private Attributes | Static Private Attributes | List of all members
meta::classify::svm_wrapper Class Reference

Wrapper class for liblinear (http://www.csie.ntu.edu.tw/~cjlin/liblinear/) and libsvm (http://www.csie.ntu.edu.tw/~cjlin/libsvm/) implementation of support vector machine classification. More...

#include <svm_wrapper.h>

Inheritance diagram for meta::classify::svm_wrapper:
meta::classify::classifier

Public Types

enum  kernel {
  None, Quadratic, Cubic, Quartic,
  RBF, Sigmoid
}
 Selects which kernel to use. More...
 

Public Member Functions

 svm_wrapper (std::shared_ptr< index::forward_index > idx, const std::string &svm_path, kernel kernel_opt=kernel::None)
 Constructor. More...
 
class_label classify (doc_id d_id) override
 Classifies a document into a specific group, as determined by training data. More...
 
void train (const std::vector< doc_id > &docs) override
 Creates a classification model based on training documents. More...
 
confusion_matrix test (const std::vector< doc_id > &docs) override
 Classifies a collection document into specific groups, as determined by training data; this function will make repeated calls to classify(). More...
 
void reset () override
 Clears any learned data from this classifier.
 
- Public Member Functions inherited from meta::classify::classifier
 classifier (std::shared_ptr< index::forward_index > idx)
 
virtual confusion_matrix cross_validate (const std::vector< doc_id > &input_docs, size_t k, bool even_split=false, int seed=1)
 Performs k-fold cross-validation on a set of documents. More...
 

Static Public Attributes

static const std::string id = "libsvm"
 The identifier for this classifier.
 

Private Attributes

const std::string svm_path_
 the path to the liblinear/libsvm library
 
kernel kernel_
 which kernel function to use for this SVM
 
std::string executable_
 used to select which executable to use (libsvm or liblinear)
 

Static Private Attributes

static const std::unordered_map< kernel, std::string, std::hash< int > > options_
 keeps track of which arguments are necessary for which kernel function
 

Additional Inherited Members

- Protected Attributes inherited from meta::classify::classifier
std::shared_ptr< index::forward_indexidx_
 the index that the classifer is run on
 

Detailed Description

Wrapper class for liblinear (http://www.csie.ntu.edu.tw/~cjlin/liblinear/) and libsvm (http://www.csie.ntu.edu.tw/~cjlin/libsvm/) implementation of support vector machine classification.

To use this class, make sure that you have checked out the libsvm-modules submodule and have compiled both libsvm and liblinear.

If no kernel is selected, liblinear is used. Otherwise, libsvm is used.

Member Enumeration Documentation

Selects which kernel to use.

"None" uses liblinear. Any other kernel uses libsvm.

Constructor & Destructor Documentation

meta::classify::svm_wrapper::svm_wrapper ( std::shared_ptr< index::forward_index idx,
const std::string &  svm_path,
kernel  kernel_opt = kernel::None 
)

Constructor.

Parameters
idxThe index to run the classifier on
svm_pathThe path to the liblinear/libsvm library
kernel_optWhich kind of kernel you want to use (default: None)

Member Function Documentation

class_label meta::classify::svm_wrapper::classify ( doc_id  d_id)
overridevirtual

Classifies a document into a specific group, as determined by training data.

Parameters
docThe document to classify
Returns
the class it belongs to

Implements meta::classify::classifier.

void meta::classify::svm_wrapper::train ( const std::vector< doc_id > &  docs)
overridevirtual

Creates a classification model based on training documents.

Parameters
docsThe training documents

Implements meta::classify::classifier.

confusion_matrix meta::classify::svm_wrapper::test ( const std::vector< doc_id > &  docs)
overridevirtual

Classifies a collection document into specific groups, as determined by training data; this function will make repeated calls to classify().

Parameters
docsThe documents to classify
Returns
a confusion_matrix detailing the performance of the classifier

Reimplemented from meta::classify::classifier.


The documentation for this class was generated from the following files: