jsat.classifiers.svm
Class DCDs
- java.lang.Object
-
- jsat.classifiers.svm.DCDs
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, BinaryScoreClassifier, Classifier, WarmClassifier, Parameterized, Regressor, WarmRegressor, SimpleWeightVectorModel, SingleWeightVectorModel
public class DCDs extends java.lang.Object implements BinaryScoreClassifier, Regressor, Parameterized, SingleWeightVectorModel, WarmClassifier, WarmRegressor
Implements Dual Coordinate Descent with shrinking (DCDs) training algorithms for a Linear L1 or L2 Support Vector Machine for binary classification and regression. NOTE: While this implementation makes use of the dual formulation only the linear kernel is ever used. The algorithm also uses the primal representation and uses the explicit formulation of w in training and classification. As such, the support vectors found are not necessary once training is complete - and will be discarded.
DCDs man be warm started by other DCDs models trained on the same data set.
See:- Hsieh, C.-J., Chang, K.-W., Lin, C.-J., Keerthi, S. S., & Sundararajan, S. (2008). A Dual Coordinate Descent Method for Large-scale Linear SVM. Proceedings of the 25th international conference on Machine learning - ICML ’08 (pp. 408–415). New York, New York, USA: ACM Press. doi:10.1145/1390156.1390208
- Ho, C.-H., & Lin, C.-J. (2012). Large-scale Linear Support Vector Regression. Journal of Machine Learning Research, 13, 3323–3348. Retrieved from here
- See Also:
DCD, Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description DCDs()Creates a new DCDL2 SVM objectDCDs(int maxIterations, boolean useL1)Creates a new DCD SVM objectDCDs(int maxIterations, double tolerance, double C, boolean useL1)Creates a new DCD SVM object
-
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.DCDsclone()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.doublegetC()Returns the penalty parameter for misclassifications.doublegetEps()Returns the epsilon insensitivity parameter used in regression problems.intgetMaxIterations()Returns the maximum number of allowed training epochsVecgetRawWeight()Returns the only weight vector used for the modelVecgetRawWeight(int index)Returns the raw weight vector associated with the given class index.doublegetScore(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.doublegetTolerance()Returns the tolerance value used to terminate earlystatic DistributionguessC(DataSet d)Guess the distribution to use for the regularization termCin a SVM.booleanisUseBias()Returnstrueif an implicit bias term is in use, orfalseif not.booleanisUseL1()Returns true if the L1 form is in useintnumWeightsVecs()Returns the number of weight vectors that can be returned.doubleregress(DataPoint data)voidsetC(double C)Sets the penalty parameter for misclassifications.voidsetEps(double eps)Sets theepsused in the epsilon insensitive loss function used when performing regression.voidsetMaxIterations(int maxIterations)Sets the maximum number of iterations allowed through the whole training set.voidsetTolerance(double tolerance)Sets the tolerance for the stopping condition when training, a small value near zero allows training to stop early when little to no additional convergence is possible.voidsetUseBias(boolean useBias)Sets whether or not an implicit bias term should be added to the inputs.voidsetUseL1(boolean useL1)Determines whether or not to use the L1 or L2 SVMbooleansupportsWeightedData()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.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)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 java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jsat.parameters.Parameterized
getParameter, getParameters
-
-
-
-
Constructor Detail
-
DCDs
public DCDs()
Creates a new DCDL2 SVM object
-
DCDs
public DCDs(int maxIterations, boolean useL1)Creates a new DCD SVM object- Parameters:
maxIterations- the maximum number of training iterationsuseL1- whether or not to use L1 or L2 form
-
DCDs
public DCDs(int maxIterations, double tolerance, double C, boolean useL1)Creates a new DCD SVM object- Parameters:
maxIterations- the maximum number of training iterationstolerance- the tolerance value for early stoppingC- the misclassification penaltyuseL1- whether or not to use L1 or L2 form
-
-
Method Detail
-
setC
public void setC(double C)
Sets the penalty parameter for misclassifications. The recommended value is 1, and values larger than 4 are not normally needed according to the original paper.- Parameters:
C- the penalty parameter in (0, Inf)
-
getC
public double getC()
Returns the penalty parameter for misclassifications.- Returns:
- the penalty parameter for misclassifications.
-
setEps
public void setEps(double eps)
Sets theepsused in the epsilon insensitive loss function used when performing regression. Errors in the output that less thanepsduring training are treated as correct.
This parameter has no impact on classification problems.- Parameters:
eps- the non-negative value to use as the error tolerance in regression
-
getEps
public double getEps()
Returns the epsilon insensitivity parameter used in regression problems.- Returns:
- the epsilon insensitivity parameter used in regression problems.
-
setTolerance
public void setTolerance(double tolerance)
Sets the tolerance for the stopping condition when training, a small value near zero allows training to stop early when little to no additional convergence is possible.- Parameters:
tolerance- the tolerance value to use to stop early
-
getTolerance
public double getTolerance()
Returns the tolerance value used to terminate early- Returns:
- the tolerance value used to terminate early
-
setUseL1
public void setUseL1(boolean useL1)
Determines whether or not to use the L1 or L2 SVM- Parameters:
useL1- true to use the L1 form, false to use the L2 form.
-
isUseL1
public boolean isUseL1()
Returns true if the L1 form is in use- Returns:
- true if the L1 form is in use
-
setMaxIterations
public void setMaxIterations(int maxIterations)
Sets the maximum number of iterations allowed through the whole training set.- Parameters:
maxIterations- the maximum number of training epochs
-
getMaxIterations
public int getMaxIterations()
Returns the maximum number of allowed training epochs- Returns:
- the maximum number of allowed training epochs
-
setUseBias
public void setUseBias(boolean useBias)
Sets whether or not an implicit bias term should be added to the inputs.- Parameters:
useBias-trueto add an implicit bias term to inputs,falseto use the input data as provided.
-
isUseBias
public boolean isUseBias()
Returnstrueif an implicit bias term is in use, orfalseif not.- Returns:
trueif an implicit bias term is in use, orfalseif not.
-
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.
-
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.
-
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
-
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
-
warmFromSameDataOnly
public boolean warmFromSameDataOnly()
Description copied from interface:WarmClassifierSome 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.
-
clone
public DCDs clone()
- Specified by:
clonein interfaceBinaryScoreClassifier- Specified by:
clonein interfaceClassifier- Specified by:
clonein interfaceRegressor- Overrides:
clonein classjava.lang.Object
-
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, boolean parallel)
-
train
public void train(RegressionDataSet dataSet)
-
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
-
guessC
public static Distribution guessC(DataSet d)
Guess the distribution to use for the regularization termCin a SVM.- Parameters:
d- the data set to get the guess for- Returns:
- the guess for the C parameter in the SVM
-
-
DataMelt 3.0 © DataMelt by jWork.ORG