MLPACK  1.0.11
logistic_regression.hpp
Go to the documentation of this file.
1 
23 #ifndef __MLPACK_METHODS_LOGISTIC_REGRESSION_LOGISTIC_REGRESSION_HPP
24 #define __MLPACK_METHODS_LOGISTIC_REGRESSION_LOGISTIC_REGRESSION_HPP
25 
26 #include <mlpack/core.hpp>
28 
30 
31 namespace mlpack {
32 namespace regression {
33 
34 template<
35  template<typename> class OptimizerType = mlpack::optimization::L_BFGS
36 >
38 {
39  public:
50  LogisticRegression(const arma::mat& predictors,
51  const arma::vec& responses,
52  const double lambda = 0);
53 
65  LogisticRegression(const arma::mat& predictors,
66  const arma::vec& responses,
67  const arma::mat& initialPoint,
68  const double lambda = 0);
69 
81  LogisticRegression(OptimizerType<LogisticRegressionFunction>& optimizer);
82 
92  LogisticRegression(const arma::vec& parameters, const double lambda = 0);
93 
95  const arma::vec& Parameters() const { return parameters; }
97  arma::vec& Parameters() { return parameters; }
98 
100  const double& Lambda() const { return lambda; }
102  double& Lambda() { return lambda; }
103 
115  void Predict(const arma::mat& predictors,
116  arma::vec& responses,
117  const double decisionBoundary = 0.5) const;
118 
133  double ComputeAccuracy(const arma::mat& predictors,
134  const arma::vec& responses,
135  const double decisionBoundary = 0.5) const;
136 
145  double ComputeError(const arma::mat& predictors,
146  const arma::vec& responses) const;
147 
148  // Returns a string representation of this object.
149  std::string ToString() const;
150 
151  private:
153  arma::vec parameters;
155  double lambda;
156 };
157 
158 }; // namespace regression
159 }; // namespace mlpack
160 
161 // Include implementation.
162 #include "logistic_regression_impl.hpp"
163 
164 #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:31
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:44
arma::vec & Parameters()
Modify the parameters (the b vector).