jsat.classifiers.svm
Class LSSVM
- java.lang.Object
-
- jsat.classifiers.svm.SupportVectorLearner
-
- jsat.classifiers.svm.LSSVM
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, BinaryScoreClassifier, Classifier, WarmClassifier, Parameterized, Regressor, WarmRegressor
public class LSSVM extends SupportVectorLearner implements BinaryScoreClassifier, Regressor, Parameterized, WarmRegressor, WarmClassifier
The Least Squares Support Vector Machine (LS-SVM) is an alternative to the standard SVM classifier for regression and binary classification problems. It can be faster to train, but is usually significantly slower to perform predictions with. This is because the LS-SVM solution is dense, so all training points become support vectors.
The LS-SVM algorithm may be warm started only from another LS-SVM object trained on the same data set.
NOTE: A SMO implementation similar toPlattSMOis used. This is done because is can easily operate without explicitly forming the whole kernel matrix. However it is recommended to use the LS-SVM when the problem size is small enough such thatSupportVectorLearner.CacheMode.FULLcan be used.
If N is the number of data points:
- Training complexity is roughly O(n^3), but can be lower for small C
- Prediction complexity is O(n)
- This implementation is multi-threaded, but scales best when there are several thousand data points per core. For smaller problems, especially when full cache mode can be used, there may be negative speedups when using the parallel training methods
See:
- Suykens, J.,&Vandewalle, J. (1999). Least Squares Support Vector Machine Classifiers. Neural processing letters, 9(3), 293–298. doi:10.1023/A:1018628609742
- Keerthi, S. S.,&Shevade, S. K. (2003). SMO algorithm for Least Squares SVM. In Proceedings of the International Joint Conference on Neural Networks (Vol. 3, pp. 2088–2093). IEEE. doi:10.1109/IJCNN.2003.1223730
- 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 LSSVM()Creates a new LS-SVM learner that uses a linear model and does not use a cacheLSSVM(KernelTrick kernel)Creates a new LS-SVM learner that does not use a cacheLSSVM(KernelTrick kernel, SupportVectorLearner.CacheMode cacheMode)Creates a new LS-SVM learnerLSSVM(LSSVM toCopy)Creates a deep copy of another LS-SVM
-
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.LSSVMclone()doublegetC()Returns the regularization parameter value 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.static DistributionguessC(DataSet d)Guess the distribution to use for the regularization termCin a LS-SVM.doubleregress(DataPoint data)voidsetC(double C)Sets the regularization constant when training.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.voidtrain(ClassificationDataSet dataSet, Classifier warmSolution)Trains the classifier and constructs a model for classification using the given data set.voidtrain(ClassificationDataSet dataSet, Classifier warmSolution, boolean parallel)Trains the classifier and constructs a model for classification using the given data set.voidtrain(RegressionDataSet dataSet, boolean parallel)voidtrain(RegressionDataSet dataSet, Regressor warmSolution)Trains the regressor and constructs a model for regression using the given data set.voidtrain(RegressionDataSet dataSet, Regressor warmSolution, boolean parallel)Trains the regressor and constructs a model for regression using the given data set.booleanwarmFromSameDataOnly()Some models can only be warm started from a solution trained on the exact same data set as the model it is warm starting from.-
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.parameters.Parameterized
getParameter, getParameters
-
Methods inherited from interface jsat.classifiers.Classifier
train
-
-
-
-
Constructor Detail
-
LSSVM
public LSSVM()
Creates a new LS-SVM learner that uses a linear model and does not use a cache
-
LSSVM
public LSSVM(KernelTrick kernel)
Creates a new LS-SVM learner that does not use a cache- Parameters:
kernel- the kernel method to use
-
LSSVM
public LSSVM(KernelTrick kernel, SupportVectorLearner.CacheMode cacheMode)
Creates a new LS-SVM learner- Parameters:
kernel- the kernel method to usecacheMode- the caching scheme to use for kernel evaluations
-
LSSVM
public LSSVM(LSSVM toCopy)
Creates a deep copy of another LS-SVM- Parameters:
toCopy- the object to copy
-
-
Method Detail
-
setC
public void setC(double C)
Sets the regularization constant when training. Lower values correspond to higher amounts of regularization.- Parameters:
C- the positive regularization parameter
-
getC
public double getC()
Returns the regularization parameter value used- Returns:
- the regularization parameter value
-
warmFromSameDataOnly
public boolean warmFromSameDataOnly()
Description copied from interface:WarmRegressorSome models can only be warm started from a solution trained on the exact same data set as the model it is warm starting from. If this is the casetruewill be returned. The behavior for training on a different data set when this is defined is undefined. It may cause an error, or it may cause the algorithm to take longer or reach a worse solution.
Whentrue, it is important that the data set be unaltered - this includes mutating the values stored or re-arranging the data points within the data set.- Specified by:
warmFromSameDataOnlyin interfaceWarmClassifier- Specified by:
warmFromSameDataOnlyin interfaceWarmRegressor- Returns:
trueif the algorithm can only be warm started from the model trained on the exact same data set.
-
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
-
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(RegressionDataSet dataSet, Regressor warmSolution, boolean parallel)
Description copied from interface:WarmRegressorTrains the regressor and constructs a model for regression 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 interfaceWarmRegressor- Parameters:
dataSet- the data set to train onwarmSolution- the solution to use to warm start this modelparallel-trueif the training should be done using multiple-cores,falsefor single threaded.
-
train
public void train(RegressionDataSet dataSet, Regressor warmSolution)
Description copied from interface:WarmRegressorTrains the regressor and constructs a model for regression using the given data set.- Specified by:
trainin interfaceWarmRegressor- Parameters:
dataSet- the data set to train onwarmSolution- the solution to use to warm start this model
-
train
public void train(ClassificationDataSet dataSet, Classifier warmSolution, boolean parallel)
Description copied from interface:WarmClassifierTrains 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 interfaceWarmClassifier- Parameters:
dataSet- the data set to train onwarmSolution- the solution to use to warm start this modelparallel-trueif the training should be done using multiple-cores,falsefor single threaded.
-
train
public void train(ClassificationDataSet dataSet, Classifier warmSolution)
Description copied from interface:WarmClassifierTrains the classifier and constructs a model for classification using the given data set.- Specified by:
trainin interfaceWarmClassifier- Parameters:
dataSet- the data set to train onwarmSolution- the solution to use to warm start this model
-
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- Specified by:
supportsWeightedDatain interfaceRegressor- Returns:
- true if the model supports weighted data, false otherwise
-
train
public void train(RegressionDataSet dataSet, boolean parallel)
-
clone
public LSSVM clone()
- Specified by:
clonein interfaceBinaryScoreClassifier- Specified by:
clonein interfaceClassifier- Specified by:
clonein interfaceRegressor- Overrides:
clonein classjava.lang.Object
-
guessC
public static Distribution guessC(DataSet d)
Guess the distribution to use for the regularization termCin a LS-SVM.- Parameters:
d- the data set to get the guess for- Returns:
- the guess for the C parameter in the LS-SVM
-
-
DataMelt 3.0 © DataMelt by jWork.ORG