ModErn Text Analysis
META Enumerates Textual Applications
|
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>
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_index > | idx_ |
the index that the classifer is run on | |
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.
Selects which kernel to use.
"None" uses liblinear. Any other kernel uses libsvm.
meta::classify::svm_wrapper::svm_wrapper | ( | std::shared_ptr< index::forward_index > | idx, |
const std::string & | svm_path, | ||
kernel | kernel_opt = kernel::None |
||
) |
Constructor.
idx | The index to run the classifier on |
svm_path | The path to the liblinear/libsvm library |
kernel_opt | Which kind of kernel you want to use (default: None) |
|
overridevirtual |
Classifies a document into a specific group, as determined by training data.
doc | The document to classify |
Implements meta::classify::classifier.
|
overridevirtual |
Creates a classification model based on training documents.
docs | The training documents |
Implements meta::classify::classifier.
|
overridevirtual |
Classifies a collection document into specific groups, as determined by training data; this function will make repeated calls to classify().
docs | The documents to classify |
Reimplemented from meta::classify::classifier.