ModErn Text Analysis
META Enumerates Textual Applications
svm_wrapper.h
Go to the documentation of this file.
1 
9 #ifndef META_SVM_WRAPPER_H_
10 #define META_SVM_WRAPPER_H_
11 
12 #include <unordered_map>
15 #include "index/forward_index.h"
16 #include "meta.h"
17 
18 namespace meta
19 {
20 namespace classify
21 {
22 
33 class svm_wrapper : public classifier
34 {
35  public:
40  enum kernel
41  {
42  None,
43  Quadratic,
44  Cubic,
45  Quartic,
46  RBF,
47  Sigmoid
48  };
49 
57  svm_wrapper(std::shared_ptr<index::forward_index> idx,
58  const std::string& svm_path, kernel kernel_opt = kernel::None);
59 
66  class_label classify(doc_id d_id) override;
67 
72  void train(const std::vector<doc_id>& docs) override;
73 
82  confusion_matrix test(const std::vector<doc_id>& docs) override;
83 
87  void reset() override;
88 
92  const static std::string id;
93 
94  private:
96  const std::string svm_path_;
97 
100  const static std::unordered_map<kernel, std::string, std::hash<int>>
102 
105 
107  std::string executable_;
108 };
109 
114 template <>
115 std::unique_ptr<classifier>
116  make_classifier<svm_wrapper>(const cpptoml::table&,
117  std::shared_ptr<index::forward_index>);
118 }
119 }
120 
121 #endif
Contains top-level namespace documentation for the META toolkit.
kernel
Selects which kernel to use.
Definition: svm_wrapper.h:40
std::string executable_
used to select which executable to use (libsvm or liblinear)
Definition: svm_wrapper.h:107
Allows interpretation of classification errors.
Definition: confusion_matrix.h:25
Wrapper class for liblinear (http://www.csie.ntu.edu.tw/~cjlin/liblinear/) and libsvm (http://www...
Definition: svm_wrapper.h:33
void reset() override
Clears any learned data from this classifier.
Definition: svm_wrapper.cpp:105
static const std::unordered_map< kernel, std::string, std::hash< int > > options_
keeps track of which arguments are necessary for which kernel function
Definition: svm_wrapper.h:101
confusion_matrix test(const std::vector< doc_id > &docs) override
Classifies a collection document into specific groups, as determined by training data; this function ...
Definition: svm_wrapper.cpp:59
const std::string svm_path_
the path to the liblinear/libsvm library
Definition: svm_wrapper.h:96
The ModErn Text Analysis toolkit is a suite of natural language processing, classification, information retreival, data mining, and other applications of text processing.
Definition: analyzer.h:24
A classifier uses a document's feature space to identify which group it belongs to.
Definition: classifier.h:24
kernel kernel_
which kernel function to use for this SVM
Definition: svm_wrapper.h:104
void train(const std::vector< doc_id > &docs) override
Creates a classification model based on training documents.
Definition: svm_wrapper.cpp:92
class_label classify(doc_id d_id) override
Classifies a document into a specific group, as determined by training data.
Definition: svm_wrapper.cpp:36
static const std::string id
The identifier for this classifier.
Definition: svm_wrapper.h:92
std::unique_ptr< classifier > make_classifier< svm_wrapper >(const cpptoml::table &, std::shared_ptr< index::forward_index >)
Specialization of the factory method used for creating svm_wrapper classifiers.
Definition: svm_wrapper.cpp:112
svm_wrapper(std::shared_ptr< index::forward_index > idx, const std::string &svm_path, kernel kernel_opt=kernel::None)
Constructor.
Definition: svm_wrapper.cpp:25