ModErn Text Analysis
META Enumerates Textual Applications
one_vs_one.h
Go to the documentation of this file.
1 
9 #ifndef META_CLASSIFY_ONE_VS_ONE_H_
10 #define META_CLASSIFY_ONE_VS_ONE_H_
11 
14 #include "meta.h"
15 
16 namespace meta
17 {
18 namespace classify
19 {
20 
28 class one_vs_one : public classifier
29 {
30  public:
42  template <class Function>
43  one_vs_one(std::shared_ptr<index::forward_index> idx, Function&& create)
44  : classifier{std::move(idx)}
45  {
46  auto labels = idx_->class_labels();
47  for (uint64_t i = 0; i < labels.size(); ++i)
48  {
49  for (uint64_t j = i + 1; j < labels.size(); ++j)
50  {
51  classifiers_.emplace_back(create(labels[i], labels[j]));
52  }
53  }
54  }
55 
56  void train(const std::vector<doc_id>& docs) override;
57 
58  class_label classify(doc_id d_id) override;
59 
60  void reset() override;
61 
65  const static std::string id;
66 
67  private:
69  std::vector<std::unique_ptr<binary_classifier>> classifiers_;
70 };
71 
76 template <>
77 std::unique_ptr<classifier>
78  make_classifier<one_vs_one>(const cpptoml::table&,
79  std::shared_ptr<index::forward_index>);
80 }
81 }
82 #endif
Contains top-level namespace documentation for the META toolkit.
one_vs_one(std::shared_ptr< index::forward_index > idx, Function &&create)
Constructs a new one_vs_one classifier using the given forward_index to retrieve document information...
Definition: one_vs_one.h:43
void reset() override
Clears any learning data associated with this classifier.
Definition: one_vs_one.cpp:64
std::shared_ptr< index::forward_index > idx_
the index that the classifer is run on
Definition: classifier.h:77
void train(const std::vector< doc_id > &docs) override
Creates a classification model based on training documents.
Definition: one_vs_one.cpp:19
Ensemble method adaptor for extending binary_classifiers to the multi-class classification case by us...
Definition: one_vs_one.h:28
std::unique_ptr< classifier > make_classifier< one_vs_one >(const cpptoml::table &, std::shared_ptr< index::forward_index >)
Specialization of the factory method used to create one_vs_all classifiers.
Definition: one_vs_one.cpp:72
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
std::vector< std::unique_ptr< binary_classifier > > classifiers_
the set of classifiers used in the ensemble
Definition: one_vs_one.h:69
class_label classify(doc_id d_id) override
Classifies a document into a specific group, as determined by training data.
Definition: one_vs_one.cpp:41
static const std::string id
The identifier for this classifier.
Definition: one_vs_one.h:65