jsat.classifiers.svm
Class DCD
- java.lang.Object
-
- jsat.classifiers.svm.DCD
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, BinaryScoreClassifier, Classifier, Parameterized, Regressor, SimpleWeightVectorModel, SingleWeightVectorModel
public class DCD extends java.lang.Object implements BinaryScoreClassifier, Regressor, Parameterized, SingleWeightVectorModel
Implements Dual Coordinate Descent (DCD) 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.
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:
DCDs, Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description DCD()Creates a new DCDL2 SVM objectDCD(int maxIterations, boolean useL1)Creates a new DCD SVM object.DCD(int maxIterations, double C, boolean useL1)Creates a new DCD SVM object
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description CategoricalResultsclassify(DataPoint data)Performs classification on the given data point.DCDclone()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.booleanisOnlineVersion()Returns whether or not the online version of the algorithm, algorithm 2 is in use.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.voidsetOnlineVersion(boolean onlineVersion)By default, Algorithm 1 is used.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(RegressionDataSet dataSet)voidtrain(RegressionDataSet dataSet, boolean parallel)-
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
-
DCD
public DCD()
Creates a new DCDL2 SVM object
-
DCD
public DCD(int maxIterations, boolean useL1)Creates a new DCD SVM object. The default C value of 1 is used as suggested in the original paper.- Parameters:
maxIterations- the maximum number of training iterationsuseL1- whether or not to use L1 or L2 form
-
DCD
public DCD(int maxIterations, double C, boolean useL1)Creates a new DCD SVM object- Parameters:
maxIterations- the maximum number of training iterationsC- the misclassification penaltyuseL1- whether or not to use L1 or L2 form
-
-
Method Detail
-
setOnlineVersion
public void setOnlineVersion(boolean onlineVersion)
By default, Algorithm 1 is used. Algorithm 2 is an "online" version that updates the dual form by only one data point at a time. This controls which version is used.- Parameters:
onlineVersion- false to use algorithm 1, true to use algorithm 2
-
isOnlineVersion
public boolean isOnlineVersion()
Returns whether or not the online version of the algorithm, algorithm 2 is in use.- Returns:
- true if algorithm 2 is in use, false if algorithm 1
-
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.
-
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.
-
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(RegressionDataSet dataSet, boolean parallel)
-
train
public void train(RegressionDataSet dataSet)
-
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
-
clone
public DCD clone()
- Specified by:
clonein interfaceBinaryScoreClassifier- Specified by:
clonein interfaceClassifier- Specified by:
clonein interfaceRegressor- Overrides:
clonein classjava.lang.Object
-
-
DataMelt 3.0 © DataMelt by jWork.ORG