Class SVClassification
- All Implemented Interfaces:
Serializable,Cloneable
The C-support vector classification (C-SVC) is the fundamental algorithm for the SVM optimization problem and its primal form is given as
$$\min_ {w, b, \xi} \frac{1}{2} w^Tw+C\sum_{i=1}^{l} \xi _i$$
$$\text{subject to} \, \, y_i(w^T \phi (x_i)+b) \geq 1- \xi _i,$$
$$ \xi_i\ge 0,i=1,\;\ldots,\;l $$
The set \(\{ (x_i,y_i): i=1,\ldots,l \}\) is the set of instance-label pairs in the training data, with \(x_i \in R^n \), \(y_i \in \{1,-1\}\), and \(l\) equal to the number of training examples. The \(\xi _i\) are the slack variables in the optimization and represent an upper bound on the number of errors. The regularization parameter \(C \, > \,0 \) acts as a tradeoff parameter between error and margin. This is the default algorithm for the classification problem.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class com.imsl.datamining.supportvectormachine.SupportVectorMachine
SupportVectorMachine.ReflectiveOperationExceptionNested classes/interfaces inherited from class com.imsl.datamining.PredictiveModel
PredictiveModel.CloneNotSupportedException, PredictiveModel.PredictiveModelException, PredictiveModel.StateChangeException, PredictiveModel.SumOfProbabilitiesNotOneException, PredictiveModel.VariableType -
Constructor Summary
ConstructorsConstructorDescriptionSVClassification(double[][] xy, int responseColumnIndex, PredictiveModel.VariableType[] varType) Constructs a support vector machine for classification (SVC).SVClassification(double[][] xy, int responseColumnIndex, PredictiveModel.VariableType[] varType, Kernel k) Constructs a support vector machine for classification (SVC).SVClassification(SVClassification classModel) Copy constructor. -
Method Summary
Modifier and TypeMethodDescriptionclone()Clones anSVClassificationpredictive model.double[]Returns the class weights.int[]Returns the weight labels array.protected SVModelPerforms the classification support vector machine optimization problem.protected double[]predictValues(SVModel model, double[][] attributeData) Generates the predicted values on the attribute data using the given support vector machine model.voidsetClassPenaltyWeights(int[] weightLabels, double[] weights) Sets the class penalty weights.protected final voidSets the configuration to that of the inputPredictiveModel.Methods inherited from class com.imsl.datamining.supportvectormachine.SupportVectorMachine
fitModel, getConvergenceTolerance, getKernel, getKernelParameters, getModel, getNuParameter, getRegularizationParameter, getWorkingArraySize, isNuFormulation, isProbability, isShrinking, predict, predict, setConvergenceTolerance, setKernel, setKernelParameters, setNuFormulation, setNuParameter, setProbability, setRegularizationParameter, setShrinking, setWorkArraySizeMethods inherited from class com.imsl.datamining.PredictiveModel
getClassCounts, getClassErrors, getClassErrors, getClassLabels, getClassProbabilities, getCostMatrix, getMaxNumberOfCategories, getMaxNumberOfIterations, getNumberOfClasses, getNumberOfColumns, getNumberOfMissing, getNumberOfPredictors, getNumberOfRows, getNumberOfUniquePredictorValues, getPredictorIndexes, getPredictorTypes, getPrintLevel, getPriorProbabilities, getRandomObject, getResponseColumnIndex, getResponseVariableAverage, getResponseVariableMostFrequentClass, getResponseVariableType, getTotalWeight, getVariableType, getWeights, getXY, isConstantSeries, isMustFitModel, isUserFixedNClasses, setClassCounts, setClassLabels, setClassProbabilities, setCostMatrix, setMaxNumberOfCategories, setMaxNumberOfIterations, setMustFitModel, setNumberOfClasses, setPredictorIndex, setPredictorTypes, setPrintLevel, setPriorProbabilities, setRandomObject, setResponseColumnIndex, setTrainingData, setVariableType, setWeights
-
Constructor Details
-
SVClassification
public SVClassification(double[][] xy, int responseColumnIndex, PredictiveModel.VariableType[] varType) Constructs a support vector machine for classification (SVC).- Parameters:
xy- adoublematrix containing the training data and associated response valuesresponseColumnIndex- anint, the column index of the response variablevarType- aPredictiveModel.VariableTypearray of length equal toxy[0].lengthcontaining the type of each variable
-
SVClassification
public SVClassification(double[][] xy, int responseColumnIndex, PredictiveModel.VariableType[] varType, Kernel k) Constructs a support vector machine for classification (SVC).- Parameters:
xy- adoublematrix containing the training data and associated response valuesresponseColumnIndex- anint, the column index of the response variablevarType- aPredictiveModel.VariableTypearray of length equal toxy[0].lengthcontaining the type of each variablek- aKernel, the kernel function
-
SVClassification
Copy constructor.- Parameters:
classModel-
-
-
Method Details
-
clone
Clones anSVClassificationpredictive model.- Specified by:
clonein classPredictiveModel- Returns:
- a clone of the
SVClassificationpredictive model
-
setClassPenaltyWeights
public void setClassPenaltyWeights(int[] weightLabels, double[] weights) Sets the class penalty weights.- Parameters:
weightLabels- anintarray containing the class labels to which the weights should be appliedweights- adoublearray of lengthweightLabels.lengthcontaining the corresponding weights. The weight values must be non-negative.Default: By default, the weight value is 1.0, leading to a penalty value of C for each class.
-
getClassPenaltyWeights
public double[] getClassPenaltyWeights()Returns the class weights.- Returns:
- a
doublearray containing the class weights
-
setConfiguration
Sets the configuration to that of the inputPredictiveModel.Note that the input
PredictiveModelobject must be the same subclass ofPredictiveModelas is this instance.- Overrides:
setConfigurationin classSupportVectorMachine- Parameters:
pm- anSVClassificationinstance- Throws:
PredictiveModel.CloneNotSupportedException- ajava.lang.CloneNotSupportedExceptionhas occurred. The original exception has been added to theSupportVectorMachine.CloneNotSupportedExceptionas a suppressed exception.Default: The class uses its default configuration as described in the different methods.
-
getClassWeightLabels
public int[] getClassWeightLabels()Returns the weight labels array.- Returns:
- an
intarray containing the class labels corresponding to the penalty weights
-
optimize
protected SVModel optimize(DataNode[][] x, double[] y, double[] w, int len, Kernel kernel) throws NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException Performs the classification support vector machine optimization problem.- Specified by:
optimizein classSupportVectorMachine- Parameters:
x- aDataNodematrix containing the attribute datay- adoublearray containing the response variablew- adoublearray containing the observation weightslen- anint, the total possible number of support vectorskernel- aKernelobject- Returns:
- an
SVModelstructure containing the fitted model - Throws:
NoSuchMethodException- thrown when a particular method cannot be foundInstantiationException- thrown when an application tries to create an instance of a class using thenewInstancemethod in classClass, but the specified class object cannot be instantiatedIllegalAccessException- thrown when an application tries to reflectively create an instance (other than an array), set or get a field, or invoke a method, but the currently executing method does not have access to the definition of the specified class, field, method or constructorInvocationTargetException- a checked exception that wraps an exception thrown by an invoked method or constructor
-
predictValues
protected double[] predictValues(SVModel model, double[][] attributeData) throws PredictiveModel.SumOfProbabilitiesNotOneException Generates the predicted values on the attribute data using the given support vector machine model.- Specified by:
predictValuesin classSupportVectorMachine- Parameters:
model- a fittedSVModelobjectattributeData- adoublematrix containing the attribute (or predictor) data- Returns:
- a
doublearray containing the predictions for each row in the input attribute data - Throws:
PredictiveModel.SumOfProbabilitiesNotOneException- the sum of probabilities is not approximately one
-