MLPACK  1.0.10
Public Member Functions | Private Attributes | List of all members
mlpack::regression::LogisticRegression< OptimizerType > Class Template Reference

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

Private Attributes

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

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 double  lambda = 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
predictorsInput training variables.
responsesOutputs resulting from input training variables.
lambdaL2-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 double  lambda = 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
predictorsInput training variables.
responsesOutputs results from input training variables.
initialPointInitial model to train with.
lambdaL2-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
optimizerInstantiated optimizer with instantiated error function.
template<template< typename > class OptimizerType = mlpack::optimization::L_BFGS>
mlpack::regression::LogisticRegression< OptimizerType >::LogisticRegression ( const arma::vec &  parameters,
const double  lambda = 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
parametersParameters making up the model.
lambdaL2-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 double  decisionBoundary = 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
predictorsInput predictors.
responsesVector of responses.
decisionBoundaryDecision 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
predictorsInput predictors.
responsesVector 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 double  decisionBoundary = 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
predictorsInput predictors.
responsesVector to put output predictions of responses into.
decisionBoundaryDecision 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().


The documentation for this class was generated from the following file: