mlpack  2.0.1
logistic_regression.hpp
Go to the documentation of this file.
1 
15 #ifndef __MLPACK_METHODS_LOGISTIC_REGRESSION_LOGISTIC_REGRESSION_HPP
16 #define __MLPACK_METHODS_LOGISTIC_REGRESSION_LOGISTIC_REGRESSION_HPP
17 
18 #include <mlpack/core.hpp>
20 
22 
23 namespace mlpack {
24 namespace regression {
25 
35 template<typename MatType = arma::mat>
37 {
38  public:
54  LogisticRegression(const MatType& predictors,
55  const arma::Row<size_t>& responses,
56  const double lambda = 0);
57 
74  LogisticRegression(const MatType& predictors,
75  const arma::Row<size_t>& responses,
76  const arma::vec& initialPoint,
77  const double lambda = 0);
78 
89  LogisticRegression(const size_t dimensionality,
90  const double lambda = 0);
91 
103  template<template<typename> class OptimizerType>
105  OptimizerType<LogisticRegressionFunction<MatType>>& optimizer);
106 
120  template<
121  template<typename> class OptimizerType = mlpack::optimization::L_BFGS
122  >
123  void Train(const MatType& predictors,
124  const arma::Row<size_t>& responses);
125 
140  template<
141  template<typename> class OptimizerType = mlpack::optimization::L_BFGS
142  >
143  void Train(OptimizerType<LogisticRegressionFunction<MatType>>& optimizer);
144 
146  const arma::vec& Parameters() const { return parameters; }
148  arma::vec& Parameters() { return parameters; }
149 
151  const double& Lambda() const { return lambda; }
153  double& Lambda() { return lambda; }
154 
166  void Predict(const MatType& predictors,
167  arma::Row<size_t>& responses,
168  const double decisionBoundary = 0.5) const;
169 
184  double ComputeAccuracy(const MatType& predictors,
185  const arma::Row<size_t>& responses,
186  const double decisionBoundary = 0.5) const;
187 
196  double ComputeError(const MatType& predictors,
197  const arma::Row<size_t>& responses) const;
198 
200  template<typename Archive>
201  void Serialize(Archive& ar, const unsigned int /* version */);
202 
203  private:
205  arma::vec parameters;
207  double lambda;
208 };
209 
210 } // namespace regression
211 } // namespace mlpack
212 
213 // Include implementation.
214 #include "logistic_regression_impl.hpp"
215 
216 #endif // __MLPACK_METHODS_LOGISTIC_REGRESSION_LOGISTIC_REGRESSION_HPP
The log-likelihood function for the logistic regression objective function.
double ComputeError(const MatType &predictors, const arma::Row< size_t > &responses) const
Compute the error of the model.
const arma::vec & Parameters() const
Return the parameters (the b vector).
Linear algebra utility functions, generally performed on matrices or vectors.
void Train(const MatType &predictors, const arma::Row< size_t > &responses)
Train the LogisticRegression model on the given input data.
void Serialize(Archive &ar, const unsigned int)
Serialize the model.
double & Lambda()
Modify the lambda value for L2-regularization.
double lambda
L2-regularization penalty parameter.
arma::vec & Parameters()
Modify the parameters (the b vector).
LogisticRegression(const MatType &predictors, const arma::Row< size_t > &responses, const double lambda=0)
Construct the LogisticRegression class with the given labeled training data.
Include all of the base components required to write MLPACK methods, and the main MLPACK Doxygen docu...
const double & Lambda() const
Return the lambda value for L2-regularization.
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...
The generic L-BFGS optimizer, which uses a back-tracking line search algorithm to minimize a function...
Definition: lbfgs.hpp:36
arma::vec parameters
Vector of trained parameters (size: dimensionality plus one).
The LogisticRegression class implements an L2-regularized logistic regression model, and supports training with multiple optimizers and classification.
void Predict(const MatType &predictors, arma::Row< size_t > &responses, const double decisionBoundary=0.5) const
Predict the responses to a given set of predictors.