jsat.classifiers.svm
Class PegasosK
- java.lang.Object
-
- jsat.classifiers.svm.SupportVectorLearner
-
- jsat.classifiers.svm.PegasosK
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, BinaryScoreClassifier, Classifier, Parameterized
public class PegasosK extends SupportVectorLearner implements BinaryScoreClassifier, Parameterized
Implements the kernelized version of thePegasosalgorithm for SVMs. Unlike standard SVM algorithms, this one relies on randomness and has no guarantee to reach the optimal solution, however it is very fast to train. Each iteration of the algorithm randomly selects one datapoint to potentially update the coefficient of.
The resulting set of support vectors may be more or less sparse than a normal SVM implementation.
Because the Pegasos algorithm is stochastic and the kernelized updates on errors given regularization, the kernelized version may have more difficulty with noisy or overlapping class distributions.
See: Shalev-Shwartz, S., Singer, Y.,&Srebro, N. (2007). Pegasos : Primal Estimated sub-GrAdient SOlver for SVM. 24th international conference on Machine learning (pp. 807–814). New York, NY: ACM. doi:10.1145/1273496.1273598- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class jsat.classifiers.svm.SupportVectorLearner
SupportVectorLearner.CacheMode
-
-
Constructor Summary
Constructors Constructor and Description PegasosK(double regularization, int iterations, KernelTrick kernel)Creates a new kernelized Pegasos SVM solverPegasosK(double regularization, int iterations, KernelTrick kernel, SupportVectorLearner.CacheMode cacheMode)Creates a new kernelized Pegasos SVM solver
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description CategoricalResultsclassify(DataPoint data)Performs classification on the given data point.PegasosKclone()intgetIterations()Returns the number of iterations used during trainingdoublegetRegularization()Returns the amount of regularization useddoublegetScore(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.voidsetIterations(int iterations)Sets the number of iterations of the algorithm to perform.voidsetRegularization(double regularization)Sets the amount of regularization to apply.booleansupportsWeightedData()Indicates whether the model knows how to train using weighted data points.voidtrain(ClassificationDataSet dataSet, boolean parallel)Trains the classifier and constructs a model for classification using the given data set.-
Methods inherited from class jsat.classifiers.svm.SupportVectorLearner
getCacheMode, getCacheValue, getKernel, setCacheMode, setCacheSize, setCacheValue, setKernel
-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jsat.classifiers.Classifier
train
-
Methods inherited from interface jsat.parameters.Parameterized
getParameter, getParameters
-
-
-
-
Constructor Detail
-
PegasosK
public PegasosK(double regularization, int iterations, KernelTrick kernel)Creates a new kernelized Pegasos SVM solver- Parameters:
regularization- the amount of regularization to apply, normally a very small positive valueiterations- the number of update iterations to performkernel- the kernel to use
-
PegasosK
public PegasosK(double regularization, int iterations, KernelTrick kernel, SupportVectorLearner.CacheMode cacheMode)Creates a new kernelized Pegasos SVM solver- Parameters:
regularization- the amount of regularization to apply, normally a very small positive valueiterations- the number of update iterations to performkernel- the kernel to usecacheMode- what type of kernel caching to use
-
-
Method Detail
-
setIterations
public void setIterations(int iterations)
Sets the number of iterations of the algorithm to perform. Each iteration may or may not update a single coefficient for a specific data point.- Parameters:
iterations- the number of learning iterations to perform
-
getIterations
public int getIterations()
Returns the number of iterations used during training- Returns:
- the number of iterations used in training
-
setRegularization
public void setRegularization(double regularization)
Sets the amount of regularization to apply. The regularization must be a positive value- Parameters:
regularization- the amount of regularization to apply
-
getRegularization
public double getRegularization()
Returns the amount of regularization used- Returns:
- the amount of regularization used
-
clone
public PegasosK clone()
- Specified by:
clonein interfaceBinaryScoreClassifier- Specified by:
clonein interfaceClassifier- Overrides:
clonein classjava.lang.Object
-
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.
-
getScore
public double getScore(DataPoint dp)
Description copied from interface:BinaryScoreClassifierReturns 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.- Specified by:
getScorein interfaceBinaryScoreClassifier- Parameters:
dp- the data point to predict the class label of- Returns:
- the score for the given data point
-
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.
-
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
-
-
DataMelt 3.0 © DataMelt by jWork.ORG