public class Pegasos extends Object implements BinaryScoreClassifier, Parameterized, SingleWeightVectorModel
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_BATCH_SIZE
The default batch size is 1
|
static int |
DEFAULT_EPOCHS
The default number of epochs is 5
|
static double |
DEFAULT_REG
The default regularization value is 1.0E-4
|
Constructor and Description |
---|
Pegasos()
Creates a new Pegasos SVM classifier using default values.
|
Pegasos(int epochs,
double reg,
int batchSize)
Creates a new Pegasos SVM classifier
|
Pegasos(Pegasos toCopy)
Copy constructor
|
Modifier and Type | Method and Description |
---|---|
CategoricalResults |
classify(DataPoint data)
Performs classification on the given data point.
|
Pegasos |
clone() |
int |
getBatchSize()
Returns the number of points used in each iteration
|
double |
getBias()
Returns the bias term used for the model, or 0 of the model does not
support or was not trained with a bias term.
|
double |
getBias(int index)
Returns the bias term used with the weight vector for the given class
index.
|
double |
getEpochs()
Returns the number of iterations of updating that will be done
|
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.
|
Vec |
getRawWeight()
Returns the only weight vector used for the model
|
Vec |
getRawWeight(int index)
Returns the raw weight vector associated with the given class index.
|
double |
getRegularization()
Returns the amount of regularization to used in training
|
double |
getScore(DataPoint dp)
Returns the numeric score for predicting a class of a given data point,
where the sign of the value indicates which class the data point is
predicted to belong to.
|
static Distribution |
guessRegularization(DataSet d)
Guess the distribution to use for the regularization term
setRegularization(double) in Pegasos. |
boolean |
isProjectionStep()
Returns whether or not the projection step is in use after each iteration
|
int |
numWeightsVecs()
Returns the number of weight vectors that can be returned.
|
void |
setBatchSize(int batchSize)
Sets the batch size used during training.
|
void |
setEpochs(int epochs)
Sets the number of iterations through the training set that will be
performed.
|
void |
setProjectionStep(boolean projectionStep)
Sets whether or not to use the projection step after each update per
iteration
|
void |
setRegularization(double reg)
Sets the regularization constant used for learning.
|
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 static final int DEFAULT_EPOCHS
public static final double DEFAULT_REG
public static final int DEFAULT_BATCH_SIZE
public Pegasos()
public Pegasos(int epochs, double reg, int batchSize)
epochs
- the number of training iterationsreg
- the regularization termbatchSize
- the batch sizepublic Pegasos(Pegasos toCopy)
toCopy
- the object to copypublic void setBatchSize(int batchSize)
batchSize
- the number of data points to use when updatingpublic int getBatchSize()
public void setEpochs(int epochs)
epochs
- the number of iterationspublic double getEpochs()
public void setProjectionStep(boolean projectionStep)
projectionStep
- whether or not to use the projection steppublic boolean isProjectionStep()
public void setRegularization(double reg)
reg
- the regularization to applypublic double getRegularization()
public Vec getRawWeight()
SingleWeightVectorModel
getRawWeight
in interface SingleWeightVectorModel
public double getBias()
SingleWeightVectorModel
getBias
in interface SingleWeightVectorModel
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 Pegasos clone()
clone
in interface BinaryScoreClassifier
clone
in interface Classifier
clone
in class Object
public CategoricalResults classify(DataPoint data)
Classifier
classify
in interface Classifier
data
- the data point to classifypublic double getScore(DataPoint dp)
BinaryScoreClassifier
getScore
in interface BinaryScoreClassifier
dp
- the data point to predict the class label ofpublic 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 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 obtainpublic static Distribution guessRegularization(DataSet d)
setRegularization(double)
in Pegasos.d
- the data set to get the guess forCopyright © 2017. All rights reserved.