ModErn Text Analysis
META Enumerates Textual Applications
logistic_regression.h
Go to the documentation of this file.
1 
9 #ifndef META_LOGISTIC_REGRESSION_H_
10 #define META_LOGISTIC_REGRESSION_H_
11 
15 #include "index/forward_index.h"
16 #include "meta.h"
17 
18 namespace meta
19 {
20 namespace classify
21 {
22 
53 {
54  public:
69  logistic_regression(const std::string& prefix,
70  std::shared_ptr<index::forward_index> idx,
71  double alpha = sgd::default_alpha,
72  double gamma = sgd::default_gamma,
73  double bias = sgd::default_bias,
74  double lambda = sgd::default_lambda,
75  uint64_t max_iter = sgd::default_max_iter);
76 
84  std::unordered_map<class_label, double> predict(doc_id d_id);
85 
86  virtual class_label classify(doc_id d_id) override;
87 
88  virtual void train(const std::vector<doc_id>& docs) override;
89 
90  virtual void reset() override;
91 
93  const static std::string id;
94 
95  private:
97  std::unordered_map<class_label, sgd> classifiers_;
99  class_label pivot_;
100 };
101 
106 template <>
107 std::unique_ptr<classifier>
108  make_classifier<logistic_regression>(const cpptoml::table&,
109  std::shared_ptr<index::forward_index>);
110 }
111 }
112 #endif
static const constexpr double default_gamma
The default parameter.
Definition: sgd.h:34
Contains top-level namespace documentation for the META toolkit.
class_label pivot_
the class chosen to be the pivot element
Definition: logistic_regression.h:99
logistic_regression(const std::string &prefix, std::shared_ptr< index::forward_index > idx, double alpha=sgd::default_alpha, double gamma=sgd::default_gamma, double bias=sgd::default_bias, double lambda=sgd::default_lambda, uint64_t max_iter=sgd::default_max_iter)
Definition: logistic_regression.cpp:19
Multinomial logistic regression.
Definition: logistic_regression.h:52
std::unordered_map< class_label, double > predict(doc_id d_id)
Obtains the probability that the given document belongs to each class.
Definition: logistic_regression.cpp:38
static const constexpr size_t default_max_iter
The default number of allowed iterations.
Definition: sgd.h:40
static const std::string id
the identifier for this classifier
Definition: logistic_regression.h:93
virtual class_label classify(doc_id d_id) override
Classifies a document into a specific group, as determined by training data.
Definition: logistic_regression.cpp:55
static const constexpr double default_alpha
The default parameter.
Definition: sgd.h:32
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
std::unique_ptr< classifier > make_classifier< logistic_regression >(const cpptoml::table &, std::shared_ptr< index::forward_index >)
Specialization of the factory method used for creating logistic_regression classifiers.
Definition: logistic_regression.cpp:91
virtual void train(const std::vector< doc_id > &docs) override
Creates a classification model based on training documents.
Definition: logistic_regression.cpp:67
A classifier uses a document's feature space to identify which group it belongs to.
Definition: classifier.h:24
std::unordered_map< class_label, sgd > classifiers_
the set of independent classifiers
Definition: logistic_regression.h:97
static const constexpr double default_bias
The default parameter.
Definition: sgd.h:36
virtual void reset() override
Clears any learning data associated with this classifier.
Definition: logistic_regression.cpp:84
static const constexpr double default_lambda
The default parameter.
Definition: sgd.h:38