mlpack  1.0.12
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 
26 template<
27  template<typename> class OptimizerType = mlpack::optimization::L_BFGS
28 >
30 {
31  public:
42  LogisticRegression(const arma::mat& predictors,
43  const arma::vec& responses,
44  const double lambda = 0);
45 
57  LogisticRegression(const arma::mat& predictors,
58  const arma::vec& responses,
59  const arma::mat& initialPoint,
60  const double lambda = 0);
61 
73  LogisticRegression(OptimizerType<LogisticRegressionFunction>& optimizer);
74 
84  LogisticRegression(const arma::vec& parameters, const double lambda = 0);
85 
87  const arma::vec& Parameters() const { return parameters; }
89  arma::vec& Parameters() { return parameters; }
90 
92  const double& Lambda() const { return lambda; }
94  double& Lambda() { return lambda; }
95 
107  void Predict(const arma::mat& predictors,
108  arma::vec& responses,
109  const double decisionBoundary = 0.5) const;
110 
125  double ComputeAccuracy(const arma::mat& predictors,
126  const arma::vec& responses,
127  const double decisionBoundary = 0.5) const;
128 
137  double ComputeError(const arma::mat& predictors,
138  const arma::vec& responses) const;
139 
140  // Returns a string representation of this object.
141  std::string ToString() const;
142 
143  private:
145  arma::vec parameters;
147  double lambda;
148 };
149 
150 }; // namespace regression
151 }; // namespace mlpack
152 
153 // Include implementation.
154 #include "logistic_regression_impl.hpp"
155 
156 #endif // __MLPACK_METHODS_LOGISTIC_REGRESSION_LOGISTIC_REGRESSION_HPP
double & Lambda()
Modify the lambda value for L2-regularization.
arma::vec parameters
Vector of trained parameters.
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: load.hpp:23
LogisticRegression(const arma::mat &predictors, const arma::vec &responses, const double lambda=0)
Construct the LogisticRegression class with the given labeled training data.
void Predict(const arma::mat &predictors, arma::vec &responses, const double decisionBoundary=0.5) const
Predict the responses to a given set of predictors.
const arma::vec & Parameters() const
Return the parameters (the b vector).
double ComputeAccuracy(const arma::mat &predictors, const arma::vec &responses, const double decisionBoundary=0.5) const
Compute the accuracy of the model on the given predictors and responses, optionally using the given d...
const double & Lambda() const
Return the lambda value for L2-regularization.
double lambda
L2-regularization penalty parameter.
double ComputeError(const arma::mat &predictors, const arma::vec &responses) const
Compute the error of the model.
The generic L-BFGS optimizer, which uses a back-tracking line search algorithm to minimize a function...
Definition: lbfgs.hpp:36
arma::vec & Parameters()
Modify the parameters (the b vector).