Trainer for Logistic regression. More...
#include <shark/Algorithms/Trainers/LogisticRegression.h>
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, LabelType > | WeightedDatasetType |
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 ¶m) |
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 () |
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.
typedef base_type::DatasetType shark::LogisticRegression< InputVectorType >::DatasetType |
Definition at line 70 of file LogisticRegression.h.
typedef base_type::ModelType shark::LogisticRegression< InputVectorType >::ModelType |
Definition at line 69 of file LogisticRegression.h.
typedef base_type::WeightedDatasetType shark::LogisticRegression< InputVectorType >::WeightedDatasetType |
Definition at line 71 of file LogisticRegression.h.
|
inline |
Constructor.
lambda1 | value of the 1-norm regularization parameter (see class description) |
lambda2 | value of the 2-norm regularization parameter (see class description) |
lbias | whether to train with bias or not |
accuracy | stopping 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().
|
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().
|
inline |
Return the current setting of the l1-regularization parameter.
Definition at line 92 of file LogisticRegression.h.
Referenced by shark::LogisticRegression< InputVectorType >::LogisticRegression().
|
inline |
Return the current setting of the l2-regularization parameter.
Definition at line 97 of file LogisticRegression.h.
Referenced by shark::LogisticRegression< InputVectorType >::LogisticRegression().
|
inlinevirtual |
From INameable: return the class name.
Reimplemented from shark::INameable.
Definition at line 87 of file LogisticRegression.h.
|
inlinevirtual |
Return the number of parameters (one in this case).
Reimplemented from shark::IParameterizable<>.
Definition at line 136 of file LogisticRegression.h.
|
inlinevirtual |
Get the regularization parameters lambda1 and lambda2 through the IParameterizable interface.
Reimplemented from shark::IParameterizable<>.
Definition at line 124 of file LogisticRegression.h.
|
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().
|
inline |
Set the l1-regularization parameter.
Definition at line 102 of file LogisticRegression.h.
References lambda, and SHARK_RUNTIME_CHECK.
Referenced by shark::LogisticRegression< InputVectorType >::LogisticRegression(), and shark::LogisticRegression< InputVectorType >::setParameterVector().
|
inline |
Set the l2-regularization parameter.
Definition at line 108 of file LogisticRegression.h.
References lambda, and SHARK_RUNTIME_CHECK.
Referenced by shark::LogisticRegression< InputVectorType >::LogisticRegression(), and shark::LogisticRegression< InputVectorType >::setParameterVector().
|
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.
|
inline |
Train a linear model with logistic regression.
Definition at line 141 of file LogisticRegression.h.
|
inline |
Train a linear model with logistic regression using weights.
Definition at line 146 of file LogisticRegression.h.
References shark::inputDimension(), and shark::numberOfClasses().