jsat.classifiers.linear
Class LogisticRegressionDCD
- java.lang.Object
-
- jsat.classifiers.linear.LogisticRegressionDCD
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, Classifier, Parameterized, SimpleWeightVectorModel, SingleWeightVectorModel
public class LogisticRegressionDCD extends java.lang.Object implements Classifier, Parameterized, SingleWeightVectorModel
This provides an implementation of regularized logistic regression using Dual Coordinate Descent. This algorithm works well on both dense and sparse large data sets.
The regularized problem is of the form:
C Σ log(1+exp(-yiwTxi)) + wTw/2
See:
Yu, H.-F., Huang, F.-L.,&Lin, C.-J. (2010). Dual Coordinate Descent Methods for Logistic Regression and Maximum Entropy Models. Machine Learning, 85(1-2), 41–75. doi:10.1007/s10994-010-5221-8- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description LogisticRegressionDCD()Creates a new Logistic Regression learner that does no more than 100 training iterations with a default regularization tradeoff of C = 1LogisticRegressionDCD(double C)Creates a new Logistic Regression learner that does no more than 100 training iterations.LogisticRegressionDCD(double C, int maxIterations)Creates a new Logistic Regression learner
-
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.Classifierclone()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()Returns the regularization tradeoff parameterintgetMaxIterations()Returns the maximum number of iterations the algorithm is allowed to runVecgetRawWeight()Returns the only weight vector used for the modelVecgetRawWeight(int index)Returns the raw weight vector associated with the given class index.VecgetWeightVec()Returns the weight vector used to compute results via a dot product.static DistributionguessC(DataSet d)Guess the distribution to use for the regularization termCin Logistic Regression.booleanisUseBias()Returnstrueif a bias term is in use,falseotherwise.intnumWeightsVecs()Returns the number of weight vectors that can be returned.voidsetC(double C)Sets the regularization trade-off term.voidsetMaxIterations(int maxIterations)Sets the maximum number of iterations the algorithm is allowed to run for.voidsetUseBias(boolean useBias)Sets whether or not an implicit bias term should be 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.-
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
-
-
-
-
Constructor Detail
-
LogisticRegressionDCD
public LogisticRegressionDCD()
Creates a new Logistic Regression learner that does no more than 100 training iterations with a default regularization tradeoff of C = 1
-
LogisticRegressionDCD
public LogisticRegressionDCD(double C)
Creates a new Logistic Regression learner that does no more than 100 training iterations.- Parameters:
C- the regularization tradeoff term
-
LogisticRegressionDCD
public LogisticRegressionDCD(double C, int maxIterations)Creates a new Logistic Regression learner- Parameters:
C- the regularization tradeoff termmaxIterations- the maximum number of iterations through the data set
-
-
Method Detail
-
setC
public void setC(double C)
Sets the regularization trade-off term. larger values reduce the amount of regularization, and smaller values increase the regularization.- Parameters:
C- the positive regularization tradeoff value
-
getC
public double getC()
Returns the regularization tradeoff parameter- Returns:
- the regularization tradeoff parameter
-
setMaxIterations
public void setMaxIterations(int maxIterations)
Sets the maximum number of iterations the algorithm is allowed to run for.- Parameters:
maxIterations- the maximum number of iterations
-
getMaxIterations
public int getMaxIterations()
Returns the maximum number of iterations the algorithm is allowed to run- Returns:
- the maximum number of iterations the algorithm is allowed to run
-
setUseBias
public void setUseBias(boolean useBias)
Sets whether or not an implicit bias term should be added to the model.- Parameters:
useBias-trueto add a bias term,falseto exclude the bias term.
-
isUseBias
public boolean isUseBias()
Returnstrueif a bias term is in use,falseotherwise.- Returns:
trueif a bias term is in use,falseotherwise.
-
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.
-
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)
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 Classifier clone()
- Specified by:
clonein interfaceClassifier- Overrides:
clonein classjava.lang.Object
-
getWeightVec
public Vec getWeightVec()
Returns the weight vector used to compute results via a dot product.
Do not modify this value, or you will alter the results returned.- Returns:
- the learned weight vector for prediction
-
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