logistic_regression.hpp
Go to the documentation of this file.
1 
14 #ifndef MLPACK_METHODS_LOGISTIC_REGRESSION_LOGISTIC_REGRESSION_HPP
15 #define MLPACK_METHODS_LOGISTIC_REGRESSION_LOGISTIC_REGRESSION_HPP
16 
17 #include <mlpack/prereqs.hpp>
18 #include <ensmallen.hpp>
19 
21 
22 namespace mlpack {
23 namespace regression {
24 
38 template<typename MatType = arma::mat>
40 {
41  public:
57  LogisticRegression(const MatType& predictors,
58  const arma::Row<size_t>& responses,
59  const double lambda = 0);
60 
77  LogisticRegression(const MatType& predictors,
78  const arma::Row<size_t>& responses,
79  const arma::rowvec& initialPoint,
80  const double lambda = 0);
81 
92  LogisticRegression(const size_t dimensionality = 0,
93  const double lambda = 0);
94 
110  template<typename OptimizerType>
111  LogisticRegression(const MatType& predictors,
112  const arma::Row<size_t>& responses,
113  OptimizerType& optimizer,
114  const double lambda);
115 
133  template<typename OptimizerType = ens::L_BFGS, typename... CallbackTypes>
134  double Train(const MatType& predictors,
135  const arma::Row<size_t>& responses,
136  CallbackTypes&&... callbacks);
137 
159  template<typename OptimizerType, typename... CallbackTypes>
160  double Train(const MatType& predictors,
161  const arma::Row<size_t>& responses,
162  OptimizerType& optimizer,
163  CallbackTypes&&... callbacks);
164 
166  const arma::rowvec& Parameters() const { return parameters; }
168  arma::rowvec& Parameters() { return parameters; }
169 
171  const double& Lambda() const { return lambda; }
173  double& Lambda() { return lambda; }
174 
186  template<typename VecType>
187  size_t Classify(const VecType& point,
188  const double decisionBoundary = 0.5) const;
189 
201  void Classify(const MatType& dataset,
202  arma::Row<size_t>& labels,
203  const double decisionBoundary = 0.5) const;
204 
211  void Classify(const MatType& dataset,
212  arma::mat& probabilities) const;
213 
228  double ComputeAccuracy(const MatType& predictors,
229  const arma::Row<size_t>& responses,
230  const double decisionBoundary = 0.5) const;
231 
240  double ComputeError(const MatType& predictors,
241  const arma::Row<size_t>& responses) const;
242 
244  template<typename Archive>
245  void serialize(Archive& ar, const unsigned int /* version */);
246 
247  private:
249  arma::rowvec parameters;
251  double lambda;
252 };
253 
254 } // namespace regression
255 } // namespace mlpack
256 
257 // Include implementation.
258 #include "logistic_regression_impl.hpp"
259 
260 #endif // MLPACK_METHODS_LOGISTIC_REGRESSION_LOGISTIC_REGRESSION_HPP
.hpp
Definition: add_to_po.hpp:21
The core includes that mlpack expects; standard C++ includes and Armadillo.
size_t Classify(const VecType &point, const double decisionBoundary=0.5) const
Classify the given point.
LogisticRegression(const MatType &predictors, const arma::Row< size_t > &responses, const double lambda=0)
Construct the LogisticRegression class with the given labeled training data.
double ComputeAccuracy(const MatType &predictors, const arma::Row< size_t > &responses, const double decisionBoundary=0.5) const
Compute the accuracy of the model on the given predictors and responses, optionally using the given d...
arma::rowvec & Parameters()
Modify the parameters (the b vector).
double Train(const MatType &predictors, const arma::Row< size_t > &responses, CallbackTypes &&... callbacks)
Train the LogisticRegression model on the given input data.
double ComputeError(const MatType &predictors, const arma::Row< size_t > &responses) const
Compute the error of the model.
const double & Lambda() const
Return the lambda value for L2-regularization.
void serialize(Archive &ar, const unsigned int)
Serialize the model.
double & Lambda()
Modify the lambda value for L2-regularization.
const arma::rowvec & Parameters() const
Return the parameters (the b vector).
The LogisticRegression class implements an L2-regularized logistic regression model, and supports training with multiple optimizers and classification.