ModErn Text Analysis
META Enumerates Textual Applications
one_vs_all.h
Go to the documentation of this file.
1 
9 #ifndef META_CLASSIFY_ONE_VS_ALL_H_
10 #define META_CLASSIFY_ONE_VS_ALL_H_
11 
14 #include "meta.h"
15 
16 namespace meta
17 {
18 namespace classify
19 {
20 
25 class one_vs_all : public classifier
26 {
27  public:
39  template <class Function>
40  one_vs_all(std::shared_ptr<index::forward_index> idx, Function&& create)
41  : classifier{std::move(idx)}
42  {
43  for (const auto& label : idx_->class_labels())
44  classifiers_.emplace(label, create(label));
45  }
46 
47  void train(const std::vector<doc_id>& docs) override;
48 
49  class_label classify(doc_id d_id) override;
50 
51  void reset() override;
52 
56  const static std::string id;
57 
58  private:
62  std::unordered_map<class_label, std::unique_ptr<binary_classifier>>
64 };
65 
70 template <>
71 std::unique_ptr<classifier>
72  make_classifier<one_vs_all>(const cpptoml::table&,
73  std::shared_ptr<index::forward_index>);
74 }
75 }
76 #endif
Contains top-level namespace documentation for the META toolkit.
one_vs_all(std::shared_ptr< index::forward_index > idx, Function &&create)
Constructs a new one_vs_all classifier on the given index by using the given function to create binar...
Definition: one_vs_all.h:40
class_label label(const std::string &text)
Extracts a class_label from a string in libsvm format.
Definition: libsvm_parser.cpp:18
Generalizes binary classifiers to operate over multiclass types using the one vs all method...
Definition: one_vs_all.h:25
static const std::string id
The identifier for this classifier.
Definition: one_vs_all.h:56
std::shared_ptr< index::forward_index > idx_
the index that the classifer is run on
Definition: classifier.h:77
std::unordered_map< class_label, std::unique_ptr< binary_classifier > > classifiers_
The set of classifiers this ensemble uses for classification.
Definition: one_vs_all.h:63
void reset() override
Clears any learning data associated with this classifier.
Definition: one_vs_all.cpp:40
std::unique_ptr< classifier > make_classifier< one_vs_all >(const cpptoml::table &, std::shared_ptr< index::forward_index >)
Specialization of the factory method used to create one_vs_all classifiers.
Definition: one_vs_all.cpp:48
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
void train(const std::vector< doc_id > &docs) override
Creates a classification model based on training documents.
Definition: one_vs_all.cpp:17
class_label classify(doc_id d_id) override
Classifies a document into a specific group, as determined by training data.
Definition: one_vs_all.cpp:24