---
name: "mlpack_regression_LogisticRegression"
section: "3"
platform: "linux"
package: "mlpack-doc"
version: "1.0.10-1"
release: "Debian 8 (Jessie)"
platforms: ["linux"]
url: "https://new.carta.tech/mlpack_regression_LogisticRegression"
---

# mlpack\_regression\_LogisticRegression(3)

## NAME

mlpack::regression::LogisticRegression\< OptimizerType \> -

## SYNOPSIS

### Public Member Functions

**LogisticRegression** (const arma::mat &predictors, const arma::vec &responses, const double **lambda**=0)\
 *Construct the* **LogisticRegression** *class with the given labeled training data.*  **LogisticRegression** (const arma::mat &predictors, const arma::vec &responses, const arma::mat &initialPoint, const double **lambda**=0)\
 *Construct the* **LogisticRegression** *class with the given labeled training data.*  **LogisticRegression** (OptimizerType\< **LogisticRegressionFunction** \> &optimizer)\
 *Construct the* **LogisticRegression** *class with the given labeled training data.*  **LogisticRegression** (const arma::vec &**parameters**, const double **lambda**=0)\
 *Construct a logistic regression model from the given parameters, without performing any training.*  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 decision boundary.*  double **ComputeError** (const arma::mat &predictors, const arma::vec &responses) const \
 *Compute the error of the model.*  const double & **Lambda** () const \
 *Return the lambda value for L2-regularization.*  double & **Lambda** ()\
 *Modify the lambda value for L2-regularization.*  const arma::vec & **Parameters** () const \
 *Return the parameters (the b vector).*  arma::vec & **Parameters** ()\
 *Modify the parameters (the b vector).*  void **Predict** (const arma::mat &predictors, arma::vec &responses, const double decisionBoundary=0.5) const \
 *Predict the responses to a given set of predictors.*  std::string **ToString** () const \

### Private Attributes

double **lambda**\
 *L2-regularization penalty parameter.*  arma::vec **parameters**\
 *Vector of trained parameters.*

## Detailed Description

### template\<template\< typename \> class OptimizerType = mlpack::optimization::L\_BFGS\>class mlpack::regression::LogisticRegression\< OptimizerType \>

Definition at line 37 of file logistic\_regression.hpp.

## Constructor & Destructor Documentation

### template\<template\< typename \> class OptimizerType = mlpack::optimization::L\_BFGS\> mlpack::regression::LogisticRegression\< OptimizerType \>::LogisticRegression (const arma::mat &predictors, const arma::vec &responses, const doublelambda = `0`)

Construct the **LogisticRegression** class with the given labeled training data. This will train the model. Optionally, specify lambda, which is the penalty parameter for L2-regularization. If not specified, it is set to 0, which results in standard (unregularized) logistic regression.

**Parameters:**

*predictors* Input training variables. \
 *responses* Outputs resulting from input training variables. \
 *lambda* L2-regularization parameter.

### template\<template\< typename \> class OptimizerType = mlpack::optimization::L\_BFGS\> mlpack::regression::LogisticRegression\< OptimizerType \>::LogisticRegression (const arma::mat &predictors, const arma::vec &responses, const arma::mat &initialPoint, const doublelambda = `0`)

Construct the **LogisticRegression** class with the given labeled training data. This will train the model. Optionally, specify lambda, which is the penalty parameter for L2-regularization. If not specified, it is set to 0, which results in standard (unregularized) logistic regression.

**Parameters:**

*predictors* Input training variables. \
 *responses* Outputs results from input training variables. \
 *initialPoint* Initial model to train with. \
 *lambda* L2-regularization parameter.

### template\<template\< typename \> class OptimizerType = mlpack::optimization::L\_BFGS\> mlpack::regression::LogisticRegression\< OptimizerType \>::LogisticRegression (OptimizerType\< LogisticRegressionFunction \> &optimizer)

Construct the **LogisticRegression** class with the given labeled training data. This will train the model. This overload takes an already instantiated optimizer (which holds the **LogisticRegressionFunction** error function, which must also be instantiated), so that the optimizer can be configured before the training is run by this constructor. The predictors and responses and initial point are all taken from the error function contained in the optimizer.

**Parameters:**

*optimizer* Instantiated optimizer with instantiated error function.

### template\<template\< typename \> class OptimizerType = mlpack::optimization::L\_BFGS\> mlpack::regression::LogisticRegression\< OptimizerType \>::LogisticRegression (const arma::vec &parameters, const doublelambda = `0`)

Construct a logistic regression model from the given parameters, without performing any training. The lambda parameter is used for the **ComputeAccuracy()** and **ComputeError()** functions; this constructor does not train the model itself.

**Parameters:**

*parameters* Parameters making up the model. \
 *lambda* L2-regularization penalty parameter.

## Member Function Documentation

### template\<template\< typename \> class OptimizerType = mlpack::optimization::L\_BFGS\> double mlpack::regression::LogisticRegression\< OptimizerType \>::ComputeAccuracy (const arma::mat &predictors, const arma::vec &responses, const doubledecisionBoundary = `0.5`) const

Compute the accuracy of the model on the given predictors and responses, optionally using the given decision boundary. The responses should be either 0 or 1. Logistic regression returns a value between 0 and 1. If the value is greater than the decision boundary, the response is taken to be 1; otherwise, it is 0. By default, the decision boundary is 0.5.

The accuracy is returned as a percentage, between 0 and 100.

**Parameters:**

*predictors* Input predictors. \
 *responses* Vector of responses. \
 *decisionBoundary* Decision boundary (default 0.5).

**Returns:**

Percentage of responses that are predicted correctly.

### template\<template\< typename \> class OptimizerType = mlpack::optimization::L\_BFGS\> double mlpack::regression::LogisticRegression\< OptimizerType \>::ComputeError (const arma::mat &predictors, const arma::vec &responses) const

Compute the error of the model. This returns the negative objective function of the logistic regression log-likelihood function. For the model to be optimal, the negative log-likelihood function should be minimized.

**Parameters:**

*predictors* Input predictors. \
 *responses* Vector of responses.

### template\<template\< typename \> class OptimizerType = mlpack::optimization::L\_BFGS\> const double& mlpack::regression::LogisticRegression\< OptimizerType \>::Lambda () const` [inline]`

Return the lambda value for L2-regularization.

Definition at line 100 of file logistic\_regression.hpp.

References mlpack::regression::LogisticRegression\< OptimizerType \>::lambda.

### template\<template\< typename \> class OptimizerType = mlpack::optimization::L\_BFGS\> double& mlpack::regression::LogisticRegression\< OptimizerType \>::Lambda ()` [inline]`

Modify the lambda value for L2-regularization.

Definition at line 102 of file logistic\_regression.hpp.

References mlpack::regression::LogisticRegression\< OptimizerType \>::lambda.

### template\<template\< typename \> class OptimizerType = mlpack::optimization::L\_BFGS\> const arma::vec& mlpack::regression::LogisticRegression\< OptimizerType \>::Parameters () const` [inline]`

Return the parameters (the b vector).

Definition at line 95 of file logistic\_regression.hpp.

References mlpack::regression::LogisticRegression\< OptimizerType \>::parameters.

### template\<template\< typename \> class OptimizerType = mlpack::optimization::L\_BFGS\> arma::vec& mlpack::regression::LogisticRegression\< OptimizerType \>::Parameters ()` [inline]`

Modify the parameters (the b vector).

Definition at line 97 of file logistic\_regression.hpp.

References mlpack::regression::LogisticRegression\< OptimizerType \>::parameters.

### template\<template\< typename \> class OptimizerType = mlpack::optimization::L\_BFGS\> void mlpack::regression::LogisticRegression\< OptimizerType \>::Predict (const arma::mat &predictors, arma::vec &responses, const doubledecisionBoundary = `0.5`) const

Predict the responses to a given set of predictors. The responses will be either 0 or 1. Optionally, specify the decision boundary; logistic regression returns a value between 0 and 1. If the value is greater than the decision boundary, the response is taken to be 1; otherwise, it is 0. By default the decision boundary is 0.5.

**Parameters:**

*predictors* Input predictors. \
 *responses* Vector to put output predictions of responses into. \
 *decisionBoundary* Decision boundary (default 0.5).

### template\<template\< typename \> class OptimizerType = mlpack::optimization::L\_BFGS\> std::string mlpack::regression::LogisticRegression\< OptimizerType \>::ToString () const

## Member Data Documentation

### template\<template\< typename \> class OptimizerType = mlpack::optimization::L\_BFGS\> double mlpack::regression::LogisticRegression\< OptimizerType \>::lambda` [private]`

L2-regularization penalty parameter.

Definition at line 155 of file logistic\_regression.hpp.

Referenced by mlpack::regression::LogisticRegression\< OptimizerType \>::Lambda().

### template\<template\< typename \> class OptimizerType = mlpack::optimization::L\_BFGS\> arma::vec mlpack::regression::LogisticRegression\< OptimizerType \>::parameters` [private]`

Vector of trained parameters.

Definition at line 153 of file logistic\_regression.hpp.

Referenced by mlpack::regression::LogisticRegression\< OptimizerType \>::Parameters().

## Author

Generated automatically by Doxygen for MLPACK from the source code.
