shark::LogisticRegression< InputVectorType > Class Template Reference

Trainer for Logistic regression. More...

#include <shark/Algorithms/Trainers/LogisticRegression.h>

+ Inheritance diagram for shark::LogisticRegression< InputVectorType >:

Public Types

typedef base_type::ModelType ModelType
 
typedef base_type::DatasetType DatasetType
 
typedef base_type::WeightedDatasetType WeightedDatasetType
 
- Public Types inherited from shark::AbstractWeightedTrainer< LinearClassifier< InputVectorType > >
typedef base_type::ModelType ModelType
 
typedef base_type::InputType InputType
 
typedef base_type::LabelType LabelType
 
typedef base_type::DatasetType DatasetType
 
typedef WeightedLabeledData< InputType, LabelTypeWeightedDatasetType
 
- Public Types inherited from shark::IParameterizable<>
typedef RealVector ParameterVectorType
 

Public Member Functions

 LogisticRegression (double lambda1=0, double lambda2=0, bool bias=true, double accuracy=1.e-8)
 Constructor. More...
 
std::string name () const
 From INameable: return the class name. More...
 
double lambda1 () const
 Return the current setting of the l1-regularization parameter. More...
 
double lambda2 () const
 Return the current setting of the l2-regularization parameter. More...
 
void setLambda1 (double lambda)
 Set the l1-regularization parameter. More...
 
void setLambda2 (double lambda)
 Set the l2-regularization parameter. More...
 
double accuracy () const
 Return the current setting of the accuracy (maximal gradient component of the optimization problem). More...
 
void setAccuracy (double accuracy)
 Set the accuracy (maximal gradient component of the optimization problem). More...
 
RealVector parameterVector () const
 Get the regularization parameters lambda1 and lambda2 through the IParameterizable interface. More...
 
void setParameterVector (const RealVector &param)
 Set the regularization parameters lambda1 and lambda2 through the IParameterizable interface. More...
 
size_t numberOfParameters () const
 Return the number of parameters (one in this case). More...
 
void train (ModelType &model, DatasetType const &dataset)
 Train a linear model with logistic regression. More...
 
void train (ModelType &model, WeightedDatasetType const &dataset)
 Train a linear model with logistic regression using weights. More...
 
- Public Member Functions inherited from shark::AbstractWeightedTrainer< LinearClassifier< InputVectorType > >
virtual void train (ModelType &model, WeightedDatasetType const &dataset)=0
 Executes the algorithm and trains a model on the given weighted data. More...
 
virtual void train (ModelType &model, DatasetType const &dataset)
 Executes the algorithm and trains a model on the given unweighted data. More...
 
- Public Member Functions inherited from shark::INameable
virtual ~INameable ()
 
- Public Member Functions inherited from shark::ISerializable
virtual ~ISerializable ()
 Virtual d'tor. More...
 
virtual void read (InArchive &archive)
 Read the component from the supplied archive. More...
 
virtual void write (OutArchive &archive) const
 Write the component to the supplied archive. More...
 
void load (InArchive &archive, unsigned int version)
 Versioned loading of components, calls read(...). More...
 
void save (OutArchive &archive, unsigned int version) const
 Versioned storing of components, calls write(...). More...
 
 BOOST_SERIALIZATION_SPLIT_MEMBER ()
 
- Public Member Functions inherited from shark::IParameterizable<>
virtual ~IParameterizable ()
 

Detailed Description

template<class InputVectorType = RealVector>
class shark::LogisticRegression< InputVectorType >

Trainer for Logistic regression.

Logistic regression solves the following optimization problem:

\[ \min_{w,b} \sum_i u_i l(y_i,f(x_i^Tw+b)) +\lambda_1 |w|_1 +\lambda_2 |w|^2_2 \]

Where \(l\) is the cross-entropy loss and \(u_i\) are individual weuights for each point(assumed to be 1). Logistic regression is one of the most well known machine learning algorithms for classification using linear models.

The solver is based on LBFGS for the case where no l1-regularization is used. Otherwise the problem is transformed into a constrained problem and the constrined-LBFGS algorithm is used. This is one of the most efficient solvers for logistic regression as long as the number of data points is not too large.

Definition at line 64 of file LogisticRegression.h.

Member Typedef Documentation

◆ DatasetType

template<class InputVectorType = RealVector>
typedef base_type::DatasetType shark::LogisticRegression< InputVectorType >::DatasetType

Definition at line 70 of file LogisticRegression.h.

◆ ModelType

template<class InputVectorType = RealVector>
typedef base_type::ModelType shark::LogisticRegression< InputVectorType >::ModelType

Definition at line 69 of file LogisticRegression.h.

◆ WeightedDatasetType

template<class InputVectorType = RealVector>
typedef base_type::WeightedDatasetType shark::LogisticRegression< InputVectorType >::WeightedDatasetType

Definition at line 71 of file LogisticRegression.h.

Constructor & Destructor Documentation

◆ LogisticRegression()

template<class InputVectorType = RealVector>
shark::LogisticRegression< InputVectorType >::LogisticRegression ( double  lambda1 = 0,
double  lambda2 = 0,
bool  bias = true,
double  accuracy = 1.e-8 
)
inline

Constructor.

Parameters
lambda1value of the 1-norm regularization parameter (see class description)
lambda2value of the 2-norm regularization parameter (see class description)
lbiaswhether to train with bias or not
accuracystopping criterion for the iterative solver, maximal gradient component of the objective function (see class description)

Definition at line 79 of file LogisticRegression.h.

References shark::LogisticRegression< InputVectorType >::accuracy(), shark::LogisticRegression< InputVectorType >::lambda1(), shark::LogisticRegression< InputVectorType >::lambda2(), shark::LogisticRegression< InputVectorType >::setAccuracy(), shark::LogisticRegression< InputVectorType >::setLambda1(), and shark::LogisticRegression< InputVectorType >::setLambda2().

Member Function Documentation

◆ accuracy()

template<class InputVectorType = RealVector>
double shark::LogisticRegression< InputVectorType >::accuracy ( ) const
inline

Return the current setting of the accuracy (maximal gradient component of the optimization problem).

Definition at line 113 of file LogisticRegression.h.

Referenced by shark::LogisticRegression< InputVectorType >::LogisticRegression(), and shark::LogisticRegression< InputVectorType >::setAccuracy().

◆ lambda1()

template<class InputVectorType = RealVector>
double shark::LogisticRegression< InputVectorType >::lambda1 ( ) const
inline

Return the current setting of the l1-regularization parameter.

Definition at line 92 of file LogisticRegression.h.

Referenced by shark::LogisticRegression< InputVectorType >::LogisticRegression().

◆ lambda2()

template<class InputVectorType = RealVector>
double shark::LogisticRegression< InputVectorType >::lambda2 ( ) const
inline

Return the current setting of the l2-regularization parameter.

Definition at line 97 of file LogisticRegression.h.

Referenced by shark::LogisticRegression< InputVectorType >::LogisticRegression().

◆ name()

template<class InputVectorType = RealVector>
std::string shark::LogisticRegression< InputVectorType >::name ( ) const
inlinevirtual

From INameable: return the class name.

Reimplemented from shark::INameable.

Definition at line 87 of file LogisticRegression.h.

◆ numberOfParameters()

template<class InputVectorType = RealVector>
size_t shark::LogisticRegression< InputVectorType >::numberOfParameters ( ) const
inlinevirtual

Return the number of parameters (one in this case).

Reimplemented from shark::IParameterizable<>.

Definition at line 136 of file LogisticRegression.h.

◆ parameterVector()

template<class InputVectorType = RealVector>
RealVector shark::LogisticRegression< InputVectorType >::parameterVector ( ) const
inlinevirtual

Get the regularization parameters lambda1 and lambda2 through the IParameterizable interface.

Reimplemented from shark::IParameterizable<>.

Definition at line 124 of file LogisticRegression.h.

◆ setAccuracy()

template<class InputVectorType = RealVector>
void shark::LogisticRegression< InputVectorType >::setAccuracy ( double  accuracy)
inline

Set the accuracy (maximal gradient component of the optimization problem).

Definition at line 118 of file LogisticRegression.h.

References shark::LogisticRegression< InputVectorType >::accuracy(), and SHARK_RUNTIME_CHECK.

Referenced by shark::LogisticRegression< InputVectorType >::LogisticRegression().

◆ setLambda1()

template<class InputVectorType = RealVector>
void shark::LogisticRegression< InputVectorType >::setLambda1 ( double  lambda)
inline

◆ setLambda2()

template<class InputVectorType = RealVector>
void shark::LogisticRegression< InputVectorType >::setLambda2 ( double  lambda)
inline

◆ setParameterVector()

template<class InputVectorType = RealVector>
void shark::LogisticRegression< InputVectorType >::setParameterVector ( const RealVector &  param)
inlinevirtual

Set the regularization parameters lambda1 and lambda2 through the IParameterizable interface.

Reimplemented from shark::IParameterizable<>.

Definition at line 129 of file LogisticRegression.h.

References shark::LogisticRegression< InputVectorType >::setLambda1(), shark::LogisticRegression< InputVectorType >::setLambda2(), and SIZE_CHECK.

◆ train() [1/2]

template<class InputVectorType = RealVector>
void shark::LogisticRegression< InputVectorType >::train ( ModelType model,
DatasetType const &  dataset 
)
inline

Train a linear model with logistic regression.

Definition at line 141 of file LogisticRegression.h.

◆ train() [2/2]

template<class InputVectorType = RealVector>
void shark::LogisticRegression< InputVectorType >::train ( ModelType model,
WeightedDatasetType const &  dataset 
)
inline

Train a linear model with logistic regression using weights.

Definition at line 146 of file LogisticRegression.h.

References shark::inputDimension(), and shark::numberOfClasses().


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