public class StochasticMultinomialLogisticRegression extends Object implements Classifier, Parameterized, SimpleWeightVectorModel
Modifier and Type | Class and Description |
---|---|
static class |
StochasticMultinomialLogisticRegression.Prior
Represents a prior of the coefficients that can be applied to perform
regularization.
|
Modifier | Constructor and Description |
---|---|
|
StochasticMultinomialLogisticRegression()
Creates a new Stochastic Multinomial Logistic Regression that uses a
StochasticMultinomialLogisticRegression.Prior.GAUSSIAN prior with a regularization scale of 1e-6. |
|
StochasticMultinomialLogisticRegression(double initialLearningRate,
int epochs)
Creates a new Stochastic Multinomial Logistic Regression that uses a
StochasticMultinomialLogisticRegression.Prior.GAUSSIAN prior with a regularization scale of 1e-6. |
|
StochasticMultinomialLogisticRegression(double initialLearningRate,
int epochs,
double regularization,
StochasticMultinomialLogisticRegression.Prior prior)
Creates a new Stochastic Multinomial Logistic Regression object
|
protected |
StochasticMultinomialLogisticRegression(StochasticMultinomialLogisticRegression toClone)
Copy constructor
|
Modifier and Type | Method and Description |
---|---|
CategoricalResults |
classify(DataPoint data)
Performs classification on the given data point.
|
Classifier |
clone() |
double |
getAlpha()
Returns the extra parameter value
|
double |
getBias(int index)
Returns the bias term used with the weight vector for the given class
index.
|
Vec |
getCoefficientVector(int id)
Returns the raw coefficient vector used without the bias term.
|
int |
getEpochs()
Returns the maximum number of epochs
|
double |
getInitialLearningRate()
Returns the current initial learning rate
|
DecayRate |
getLearningRateDecay()
Returns the decay rate in use
|
int |
getMiniBatchSize()
Returns the number of data points used to perform each gradient update
|
Parameter |
getParameter(String paramName)
Returns the parameter with the given name.
|
List<Parameter> |
getParameters()
Returns the list of parameters that can be altered for this learner.
|
StochasticMultinomialLogisticRegression.Prior |
getPrior()
Returns the prior used for regularization
|
Vec |
getRawWeight(int index)
Returns the raw weight vector associated with the given class index.
|
double |
getRegularization()
Returns the regularization coefficient in use
|
double |
getTolerance()
Returns the minimum tolerance for early stopping.
|
boolean |
isClipping()
Returns whether or not coefficient clipping is on.
|
boolean |
isStandardized()
Returns whether or not the input is standardized for the priors
|
boolean |
isUseBias()
Returns
true if the bias term is in use |
int |
numWeightsVecs()
Returns the number of weight vectors that can be returned.
|
void |
setAlpha(double alpha)
Sets the extra parameter alpha.
|
void |
setClipping(boolean clipping)
Sets whether or not the clip changes in coefficient values caused by
regularization so that they can not make the coefficients go from
positive to negative or negative to positive.
|
void |
setEpochs(int epochs)
Sets the maximum number of epochs that occur in each iteration.
|
void |
setInitialLearningRate(double initialLearningRate)
Sets the initial learning rate to use for the first epoch.
|
void |
setLearningRateDecay(DecayRate learningRateDecay)
Sets the decay rate used to reduce the learning rate after each epoch.
|
void |
setMiniBatchSize(int miniBatchSize)
Sets the amount of data points used to form each gradient update.
|
void |
setPrior(StochasticMultinomialLogisticRegression.Prior prior)
Sets the prior used to perform regularization
|
void |
setRegularization(double regularization)
Sets the coefficient applied to the regularization penalty at each
update.
|
void |
setStandardized(boolean standardized)
Sets whether or not to perform implicit standardization of the feature
values when performing regularization by the prior.
|
void |
setTolerance(double tolerance)
Sets the tolerance that determines when the training stops early because
the change has become too insignificant.
|
void |
setUseBias(boolean useBias)
Sets whether or not to learn the bias term for a model.
|
boolean |
supportsWeightedData()
Indicates whether the model knows how to train using weighted data points.
|
void |
trainC(ClassificationDataSet dataSet)
Trains the classifier and constructs a model for classification using the
given data set.
|
void |
trainC(ClassificationDataSet dataSet,
ExecutorService threadPool)
Trains the classifier and constructs a model for classification using the
given data set.
|
public StochasticMultinomialLogisticRegression(double initialLearningRate, int epochs, double regularization, StochasticMultinomialLogisticRegression.Prior prior)
initialLearningRate
- the initial learning rate to useepochs
- the maximum number of training epochs to go throughregularization
- the scale factor applied to the regularization termprior
- the prior to use for regularizationpublic StochasticMultinomialLogisticRegression(double initialLearningRate, int epochs)
StochasticMultinomialLogisticRegression.Prior.GAUSSIAN
prior with a regularization scale of 1e-6.initialLearningRate
- the initial learning rate to useepochs
- the maximum number of training epochs to go throughpublic StochasticMultinomialLogisticRegression()
StochasticMultinomialLogisticRegression.Prior.GAUSSIAN
prior with a regularization scale of 1e-6. It
will do at most 50 epochs with a learning rate of 0.1protected StochasticMultinomialLogisticRegression(StochasticMultinomialLogisticRegression toClone)
toClone
- the classifier to create a copy ofpublic void setUseBias(boolean useBias)
useBias
- true
if the bias term should be used,
false
otherwisepublic boolean isUseBias()
true
if the bias term is in usetrue
if the bias term is in usepublic void setEpochs(int epochs)
epochs
- the maximum number of epochs to trainpublic int getEpochs()
public void setAlpha(double alpha)
StochasticMultinomialLogisticRegression.Prior.CAUCHY
and
StochasticMultinomialLogisticRegression.Prior.ELASTIC
. If these two priors are not in use, the value is
ignored.alpha
- the extra parameter value to use. Must be positivepublic double getAlpha()
public void setClipping(boolean clipping)
clipping
- true
if clipping should be used, false otherwisepublic boolean isClipping()
true
if clipping is on.public void setInitialLearningRate(double initialLearningRate)
decay rate
in use.initialLearningRate
- the initial learning rate to usepublic double getInitialLearningRate()
public void setLearningRateDecay(DecayRate learningRateDecay)
learningRateDecay
- the decay rate to usepublic DecayRate getLearningRateDecay()
public void setRegularization(double regularization)
regularization
- the non negative regularization coefficient to applypublic double getRegularization()
public void setPrior(StochasticMultinomialLogisticRegression.Prior prior)
prior
- the prior to usepublic StochasticMultinomialLogisticRegression.Prior getPrior()
public void setTolerance(double tolerance)
tolerance
- the minimum change in log likelihood to stop trainingpublic double getTolerance()
public void setStandardized(boolean standardized)
standardized
- true
if the input will be standardized,
false
if ti will be left as is.public boolean isStandardized()
true
if the input is standardized for the priorspublic void setMiniBatchSize(int miniBatchSize)
miniBatchSize
- the number of data points used to perform each
updatepublic int getMiniBatchSize()
public Vec getRawWeight(int index)
SimpleWeightVectorModel
ConstantVector
object may be returned. index = 0
should be usedgetRawWeight
in interface SimpleWeightVectorModel
index
- the class index to get the weight vector forpublic double getBias(int index)
SimpleWeightVectorModel
0
will be returned.index = 0
should be usedgetBias
in interface SimpleWeightVectorModel
index
- the class index to get the weight vector forpublic int numWeightsVecs()
SimpleWeightVectorModel
numWeightsVecs
in interface SimpleWeightVectorModel
SimpleWeightVectorModel.getRawWeight(int)
can be called.public CategoricalResults classify(DataPoint data)
Classifier
classify
in interface Classifier
data
- the data point to classifypublic void trainC(ClassificationDataSet dataSet, ExecutorService threadPool)
Classifier
trainC
in interface Classifier
dataSet
- the data set to train onthreadPool
- the source of threads to use.public void trainC(ClassificationDataSet dataSet)
Classifier
trainC
in interface Classifier
dataSet
- the data set to train onpublic boolean supportsWeightedData()
Classifier
supportsWeightedData
in interface Classifier
public Vec getCoefficientVector(int id)
id
- which coefficient vector to obtainpublic Classifier clone()
clone
in interface Classifier
clone
in class Object
public List<Parameter> getParameters()
Parameterized
getParameters
in interface Parameterized
public Parameter getParameter(String paramName)
Parameterized
getParameter
in interface Parameterized
paramName
- the name of the parameter to obtainCopyright © 2017. All rights reserved.