jsat.classifiers.linear
Class NewGLMNET
- java.lang.Object
-
- jsat.classifiers.linear.NewGLMNET
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, Classifier, WarmClassifier, Parameterized, SimpleWeightVectorModel, SingleWeightVectorModel
public class NewGLMNET extends java.lang.Object implements WarmClassifier, Parameterized, SingleWeightVectorModel
NewGLMNET is a batch method for solving Elastic Net regularized Logistic Regression problems of the form
0.5 * (1-α) ||w||2 + α * ||w||1 + C * ∑Ni=1 ℓ (wT xi + b, yi).
For α = 1, this becomes pure Lasso / L1 regularized Logistic Regression. For α = 0, this becomes pure Ridge/ L2 regularized Logistic Regression, however better solvers such asLogisticRegressionDCDare faster if using α = 0.
The default behavior is to use α=1, and includes the bias term. Including the bias term can take longer to train, but can also increase sparsity for some problems.
This algorithm can be warm started from any classifier implementing theSingleWeightVectorModelinterface.
See:- Yuan, G., Ho, C.-H.,&Lin, C. (2012). An improved GLMNET for L1-regularized logistic regression. Journal of Machine Learning Research, 13, 1999–2030. doi:10.1145/2020408.2020421
- King, R., Morgan, B. J. T., Gimenez, O., Brooks, S. P., Crc, H.,&Raton, B. (2010). Regularization Paths for Generalized Linear Models via Coordinate Descent. Journal of Statistical Software, 36(1), 1–22.
- Zou, H.,&Hastie, T. (2005). Regularization and variable selection via the elastic net. Journal of the Royal Statistical Society, Series B, 67(2), 301–320. doi:10.1111/j.1467-9868.2005.00503.x
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field and Description static doubleDEFAULT_EPSThe default tolerance for training is 0.01.static intDEFAULT_MAX_OUTER_ITERThe default number of outer iterations of the training algorithm is 100 .
-
Constructor Summary
Constructors Constructor and Description NewGLMNET()Creates a new L1 regularized Logistic Regression solver with C = 1.NewGLMNET(double C)Creates a new L1 regularized Logistic Regression solverNewGLMNET(double C, double alpha)Creates a new Elastic Net regularized Logistic Regression solver
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description CategoricalResultsclassify(DataPoint data)Performs classification on the given data point.NewGLMNETclone()doublegetAlpha()doublegetBias()Returns the bias term used for the model, or 0 of the model does not support or was not trained with a bias term.doublegetBias(int index)Returns the bias term used with the weight vector for the given class index.doublegetC()intgetMaxIters()VecgetRawWeight()Returns the only weight vector used for the modelVecgetRawWeight(int index)Returns the raw weight vector associated with the given class index.doublegetTolerance()static DistributionguessAlpha(DataSet d)Guess the distribution to use for the trade off term term(double) αin Elastic Net regularization.static DistributionguessC(DataSet d)Guess the distribution to use for the regularization termCin Logistic Regression.booleanisUseBias()intnumWeightsVecs()Returns the number of weight vectors that can be returned.voidsetAlpha(double alpha)Using α = 1 corresponds to pure L1 regularization, and α = 0 corresponds to pure L2 regularization.voidsetC(double C)Sets the regularization term, where smaller values indicate a larger regularization penalty.voidsetMaxIters(int maxOuterIters)Sets the maximum number of training iterations for the algorithm, specifically the outer loop as mentioned in the original paper.voidsetTolerance(double e_out)Sets the tolerance parameter for convergence.voidsetUseBias(boolean useBias)Controls whether or not an un-regularized bias term is added to the model.booleansupportsWeightedData()Indicates whether the model knows how to train using weighted data points.voidtrain(ClassificationDataSet dataSet)Trains the classifier and constructs a model for classification using the given data set.voidtrain(ClassificationDataSet dataSet, boolean parallel)Trains the classifier and constructs a model for classification using the given data set.voidtrain(ClassificationDataSet dataSet, Classifier warmSolution)Trains the classifier and constructs a model for classification using the given data set.voidtrain(ClassificationDataSet dataSet, Classifier warmSolution, boolean parallel)Trains the classifier and constructs a model for classification using the given data set.booleanwarmFromSameDataOnly()Some models can only be warm started from a solution trained on the exact same data set as the model it is warm starting from.-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jsat.parameters.Parameterized
getParameter, getParameters
-
-
-
-
Field Detail
-
DEFAULT_EPS
public static final double DEFAULT_EPS
The default tolerance for training is 0.01.- See Also:
- Constant Field Values
-
DEFAULT_MAX_OUTER_ITER
public static final int DEFAULT_MAX_OUTER_ITER
The default number of outer iterations of the training algorithm is 100 .- See Also:
- Constant Field Values
-
-
Constructor Detail
-
NewGLMNET
public NewGLMNET()
Creates a new L1 regularized Logistic Regression solver with C = 1.
-
NewGLMNET
public NewGLMNET(double C)
Creates a new L1 regularized Logistic Regression solver- Parameters:
C- the regularization term
-
NewGLMNET
public NewGLMNET(double C, double alpha)Creates a new Elastic Net regularized Logistic Regression solver- Parameters:
C- the regularization termalpha- the fraction of weight (in [0, 1]) to apply to L1 regularization instead of L2 regularization.
-
-
Method Detail
-
setC
public void setC(double C)
Sets the regularization term, where smaller values indicate a larger regularization penalty.- Parameters:
C- the positive regularization term
-
getC
public double getC()
- Returns:
- the regularization term
-
setAlpha
public void setAlpha(double alpha)
Using α = 1 corresponds to pure L1 regularization, and α = 0 corresponds to pure L2 regularization. Any value in-between is then an Elastic Net regularization.- Parameters:
alpha- the value in [0, 1] for determining the regularization penalty's interpolation between pure L2 and L1 regularization.
-
getAlpha
public double getAlpha()
- Returns:
- the fraction of weight (in [0, 1]) to apply to L1 regularization instead of L2 regularization.
-
setMaxIters
public void setMaxIters(int maxOuterIters)
Sets the maximum number of training iterations for the algorithm, specifically the outer loop as mentioned in the original paper. 100 is the default value used, and may need to be increased for more difficult problems.- Parameters:
maxOuterIters- the maximum number of outer iterations
-
getMaxIters
public int getMaxIters()
- Returns:
- the maximum number of training iterations
-
setTolerance
public void setTolerance(double e_out)
Sets the tolerance parameter for convergence. Smaller values will be more exact, but larger values will converge faster. The default value is fairly exact at 0.01, increasing it by an order of magnitude can often be done without hurting accuracy.- Parameters:
e_out- the tolerance parameter.
-
getTolerance
public double getTolerance()
- Returns:
- the convergence tolerance parameter
-
setUseBias
public void setUseBias(boolean useBias)
Controls whether or not an un-regularized bias term is added to the model. Using a bias term can increase runtime, especially in sparse data sets, as each data point will have work done for the implicit bias term. However the bias term is usually needed for small dimension problems, and can improve the sparsity of the solution for higher dimensional problems.- Parameters:
useBias-trueif an un-regularized bias term should be used orfalseto not use any bias term.
-
isUseBias
public boolean isUseBias()
- Returns:
trueif an un-regularized bias term will be used orfalseto not use any bias term.
-
classify
public CategoricalResults classify(DataPoint data)
Description copied from interface:ClassifierPerforms classification on the given data point.- Specified by:
classifyin interfaceClassifier- Parameters:
data- the data point to classify- Returns:
- the results of the classification.
-
train
public void train(ClassificationDataSet dataSet, boolean parallel)
Description copied from interface:ClassifierTrains the classifier and constructs a model for classification using the given data set. If the training method knows how, it will used the threadPool to conduct training in parallel. This method will block until the training has completed.- Specified by:
trainin interfaceClassifier- Parameters:
dataSet- the data set to train onparallel-trueif multiple threads should be used to train the model.falseif it should be done in a single threaded manner.
-
train
public void train(ClassificationDataSet dataSet, Classifier warmSolution, boolean parallel)
Description copied from interface:WarmClassifierTrains the classifier and constructs a model for classification using the given data set. If the training method knows how, it will used the threadPool to conduct training in parallel. This method will block until the training has completed.- Specified by:
trainin interfaceWarmClassifier- Parameters:
dataSet- the data set to train onwarmSolution- the solution to use to warm start this modelparallel-trueif the training should be done using multiple-cores,falsefor single threaded.
-
train
public void train(ClassificationDataSet dataSet, Classifier warmSolution)
Description copied from interface:WarmClassifierTrains the classifier and constructs a model for classification using the given data set.- Specified by:
trainin interfaceWarmClassifier- Parameters:
dataSet- the data set to train onwarmSolution- the solution to use to warm start this model
-
train
public void train(ClassificationDataSet dataSet)
Description copied from interface:ClassifierTrains the classifier and constructs a model for classification using the given data set.- Specified by:
trainin interfaceClassifier- Parameters:
dataSet- the data set to train on
-
supportsWeightedData
public boolean supportsWeightedData()
Description copied from interface:ClassifierIndicates whether the model knows how to train using weighted data points. If it does, the model will train assuming the weights. The values returned by this method may change depending on the parameters set for the model.- Specified by:
supportsWeightedDatain interfaceClassifier- Returns:
- true if the model supports weighted data, false otherwise
-
clone
public NewGLMNET clone()
- Specified by:
clonein interfaceClassifier- Overrides:
clonein classjava.lang.Object
-
getRawWeight
public Vec getRawWeight()
Description copied from interface:SingleWeightVectorModelReturns the only weight vector used for the model- Specified by:
getRawWeightin interfaceSingleWeightVectorModel- Returns:
- the only weight vector used for the model
-
getBias
public double getBias()
Description copied from interface:SingleWeightVectorModelReturns the bias term used for the model, or 0 of the model does not support or was not trained with a bias term.- Specified by:
getBiasin interfaceSingleWeightVectorModel- Returns:
- the bias term for the model
-
getRawWeight
public Vec getRawWeight(int index)
Description copied from interface:SimpleWeightVectorModelReturns the raw weight vector associated with the given class index. If the given class is an implicit zero vector, aConstantVectorobject may be returned.
Do not alter the returned weight vector, as it will change the model's values.
If a regression problem, onlyindex = 0should be used- Specified by:
getRawWeightin interfaceSimpleWeightVectorModel- Parameters:
index- the class index to get the weight vector for- Returns:
- the weight vector used for the specified class
-
getBias
public double getBias(int index)
Description copied from interface:SimpleWeightVectorModelReturns the bias term used with the weight vector for the given class index. If the model does not support or was not trained with bias weights,0will be returned.
If a regression problem, onlyindex = 0should be used- Specified by:
getBiasin interfaceSimpleWeightVectorModel- Parameters:
index- the class index to get the weight vector for- Returns:
- the bias term for the specified class
-
numWeightsVecs
public int numWeightsVecs()
Description copied from interface:SimpleWeightVectorModelReturns the number of weight vectors that can be returned. For binary classification problems the value may be 1 if only a single weight vector's sign is used to determine the class. For multi-class problems, the weight vector count includes the implicit zero vector (if one is being used).- Specified by:
numWeightsVecsin interfaceSimpleWeightVectorModel- Returns:
- the number of weight vectors for which
SimpleWeightVectorModel.getRawWeight(int)can be called.
-
warmFromSameDataOnly
public boolean warmFromSameDataOnly()
Description copied from interface:WarmClassifierSome models can only be warm started from a solution trained on the exact same data set as the model it is warm starting from. If this is the casetruewill be returned. The behavior for training on a different data set when this is defined is undefined. It may cause an error, or it may cause the algorithm to take longer or reach a worse solution.
Whentrue, it is important that the data set be unaltered - this includes mutating the values stored or re-arranging the data points within the data set.- Specified by:
warmFromSameDataOnlyin interfaceWarmClassifier- Returns:
trueif the algorithm can only be warm started from the model trained on the exact same data set.
-
guessAlpha
public static Distribution guessAlpha(DataSet d)
Guess the distribution to use for the trade off term term(double) αin Elastic Net regularization.- Parameters:
d- the data set to get the guess for- Returns:
- the guess for the α parameter
-
guessC
public static Distribution guessC(DataSet d)
Guess the distribution to use for the regularization termCin Logistic Regression.- Parameters:
d- the data set to get the guess for- Returns:
- the guess for the C parameter
-
-
DataMelt 3.0 © DataMelt by jWork.ORG