jsat.classifiers.linear
Class BBR
- java.lang.Object
-
- jsat.classifiers.linear.BBR
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, Classifier, Parameterized, SimpleWeightVectorModel, SingleWeightVectorModel
public class BBR extends java.lang.Object implements Classifier, Parameterized, SingleWeightVectorModel
This is an implementation of Bayesian Binary Regression for L1 and L2 regularized logistic regression. This model requires additional memory to perform efficient column wise passes on the data set, assuming the data is sparse.
BBR uses a Trust Region Newton algorithm that allows convergence to occur in a small number of iterations, but each iteration may be costly.
See: Genkin, A., Lewis, D. D.,&Madigan, D. (2007). Large-Scale Bayesian Logistic Regression for Text Categorization. Technometrics, 49(3), 291–304. doi:10.1198/004017007000000245- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class and Description static classBBR.PriorValid priors that control what type of regularization is applied
-
Constructor Summary
Constructors Constructor and Description BBR(double regularization, int maxIterations)Creates a new BBR for L1 Logistic Regression object that will use the given regularization value.BBR(double regularization, int maxIterations, BBR.Prior prior)Creates a new BBR Logistic Regression object that will use the given regularization value.BBR(int maxIterations)Creates a new BBR for L1 Logistic Regression object that will attempt to automatically determine the regularization value to use.BBR(int maxIterations, BBR.Prior prior)Creates a new BBR Logistic Regression object that will attempt to automatically determine the regularization value to use.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description CategoricalResultsclassify(DataPoint data)Performs classification on the given data point.BBRclone()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.intgetMaxIterations()Returns the maximum number of iterations allowedBBR.PriorgetPrior()Returns the regularizing prior in useVecgetRawWeight()Returns the only weight vector used for the modelVecgetRawWeight(int index)Returns the raw weight vector associated with the given class index.doublegetRegularization()Returns the regularization penalty used if the auto value is not useddoublegetTolerance()Returns the tolerance parameter that controls convergenceVecgetWeightVec()Returns the weight vector used to compute results via a dot product.booleanisAutoSetRegularization()Returns whether or not the algorithm will attempt to select the regularization term automaticallybooleanisUseBias()Returnstrueif a bias term is in use,falseotherwise.intnumWeightsVecs()Returns the number of weight vectors that can be returned.voidsetAutoSetRegularization(boolean autoSetRegularization)Sets whether or not the regularization term will be set automatically by the algorithm, which is done as specified in the original paper.voidsetMaxIterations(int maxIterations)Sets the maximum number of iterations allowed before halting the algorithm early.voidsetPrior(BBR.Prior prior)Sets the regularizing prior usedvoidsetRegularization(double regularization)Sets the regularization penalty to use if the algorithm has not been set to choose one automatically.voidsetTolerance(double tolerance)Sets the convergence tolerance target.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
-
BBR
public BBR(double regularization, int maxIterations)Creates a new BBR for L1 Logistic Regression object that will use the given regularization value.- Parameters:
regularization- the regularization penalty to applymaxIterations- the maximum number of training iterations to perform
-
BBR
public BBR(double regularization, int maxIterations, BBR.Prior prior)Creates a new BBR Logistic Regression object that will use the given regularization value.- Parameters:
regularization- the regularization penalty to applymaxIterations- the maximum number of training iterations to performprior- the prior to apply for regularization
-
BBR
public BBR(int maxIterations)
Creates a new BBR for L1 Logistic Regression object that will attempt to automatically determine the regularization value to use.- Parameters:
maxIterations- the maximum number of training iterations to perform
-
BBR
public BBR(int maxIterations, BBR.Prior prior)Creates a new BBR Logistic Regression object that will attempt to automatically determine the regularization value to use.- Parameters:
maxIterations- the maximum number of training iterations to performprior- the prior to apply for regularization
-
-
Method Detail
-
setRegularization
public void setRegularization(double regularization)
Sets the regularization penalty to use if the algorithm has not been set to choose one automatically.- Parameters:
regularization- sets the positive regularization penalty to use
-
getRegularization
public double getRegularization()
Returns the regularization penalty used if the auto value is not used- Returns:
- the regularization penalty used if the auto value is not used
-
setAutoSetRegularization
public void setAutoSetRegularization(boolean autoSetRegularization)
Sets whether or not the regularization term will be set automatically by the algorithm, which is done as specified in the original paper. This may choose a very large (and bad) value of the regularization term, and should not be used with smaller data sets. This value is chosen deterministically.
This value takes precedence over anything set withsetRegularization(double)- Parameters:
autoSetRegularization-trueto choose the regularization term automatically,falseto use whatever value was set before.
-
isAutoSetRegularization
public boolean isAutoSetRegularization()
Returns whether or not the algorithm will attempt to select the regularization term automatically- Returns:
trueif the regularization term is chosen automatically,falseotherwise.
-
setMaxIterations
public void setMaxIterations(int maxIterations)
Sets the maximum number of iterations allowed before halting the algorithm early.- Parameters:
maxIterations- the maximum number of training iterations
-
getMaxIterations
public int getMaxIterations()
Returns the maximum number of iterations allowed- Returns:
- the maximum number of iterations allowed
-
setTolerance
public void setTolerance(double tolerance)
Sets the convergence tolerance target. Relative changes that are smaller than the given tolerance will determine convergence.
The default value used is that suggested in the original paper of 0.0005- Parameters:
tolerance- the positive convergence tolerance goal
-
getTolerance
public double getTolerance()
Returns the tolerance parameter that controls convergence- Returns:
- the tolerance parameter that controls convergence
-
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.
-
setPrior
public void setPrior(BBR.Prior prior)
Sets the regularizing prior used- Parameters:
prior- the prior to use
-
getPrior
public BBR.Prior getPrior()
Returns the regularizing prior in use- Returns:
- the regularizing prior in use
-
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
-
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 BBR clone()
- Specified by:
clonein interfaceClassifier- Overrides:
clonein classjava.lang.Object
-
-
DataMelt 3.0 © DataMelt by jWork.ORG