public class SVClassification extends SupportVectorMachine implements 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.
SupportVectorMachine.ReflectiveOperationException
PredictiveModel.CloneNotSupportedException, PredictiveModel.PredictiveModelException, PredictiveModel.StateChangeException, PredictiveModel.SumOfProbabilitiesNotOneException, PredictiveModel.VariableType
Constructor and Description |
---|
SVClassification(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.
|
Modifier and Type | Method and Description |
---|---|
SVClassification |
clone()
Clones an
SVClassification predictive model. |
double[] |
getClassPenaltyWeights()
Returns the class weights.
|
int[] |
getClassWeightLabels()
Returns the weight labels array.
|
protected SVModel |
optimize(DataNode[][] x,
double[] y,
double[] w,
int len,
Kernel kernel)
Performs 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.
|
void |
setClassPenaltyWeights(int[] weightLabels,
double[] weights)
Sets the class penalty weights.
|
protected void |
setConfiguration(PredictiveModel pm)
Sets the configuration to that of the input
PredictiveModel . |
fitModel, getConvergenceTolerance, getKernel, getKernelParameters, getModel, getNuParameter, getRegularizationParameter, getWorkingArraySize, isNuFormulation, isProbability, isShrinking, predict, predict, setConvergenceTolerance, setKernel, setKernelParameters, setNuFormulation, setNuParameter, setProbability, setRegularizationParameter, setShrinking, setWorkArraySize
getClassCounts, 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, predict, setClassCounts, setClassLabels, setClassProbabilities, setCostMatrix, setMaxNumberOfCategories, setMaxNumberOfIterations, setMustFitModel, setNumberOfClasses, setPredictorIndex, setPredictorTypes, setPrintLevel, setPriorProbabilities, setRandomObject, setResponseColumnIndex, setTrainingData, setVariableType, setWeights
public SVClassification(double[][] xy, int responseColumnIndex, PredictiveModel.VariableType[] varType)
xy
- a double
matrix containing the training data and
associated response valuesresponseColumnIndex
- an int
, the column index of the
response variablevarType
- a PredictiveModel.VariableType
array of
length equal to xy[0].length
containing the type of each
variablepublic SVClassification(double[][] xy, int responseColumnIndex, PredictiveModel.VariableType[] varType, Kernel k)
xy
- a double
matrix containing the training data and
associated response valuesresponseColumnIndex
- an int
, the column index of the
response variablevarType
- a PredictiveModel.VariableType
array of
length equal to xy[0].length
containing the type of each
variablek
- a Kernel
, the kernel functionpublic SVClassification(SVClassification classModel)
classModel
- public SVClassification clone()
SVClassification
predictive model.clone
in class PredictiveModel
SVClassification
predictive modelpublic void setClassPenaltyWeights(int[] weightLabels, double[] weights)
weightLabels
- an int
array containing the class labels
to which the weights should be appliedweights
- a double
array of length
weightLabels.length
containing 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.
public double[] getClassPenaltyWeights()
double
array containing the class weightsprotected final void setConfiguration(PredictiveModel pm)
PredictiveModel
.
Note that the input PredictiveModel
object must be the same
subclass of PredictiveModel
as is this instance.
setConfiguration
in class SupportVectorMachine
pm
- an SVClassification
instanceCloneNotSupportedException
- a
java.lang.CloneNotSupportedException
has occurred. The
original exception has been added to the
SupportVectorMachine.CloneNotSupportedException
as a
suppressed exception.
Default: The class uses its default configuration as described in the different methods.
public int[] getClassWeightLabels()
int
array containing the class labels
corresponding to the penalty weightsprotected SVModel optimize(DataNode[][] x, double[] y, double[] w, int len, Kernel kernel) throws NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException
optimize
in class SupportVectorMachine
x
- a DataNode
matrix containing the attribute datay
- a double
array containing the response variablew
- a double
array containing the observation weightslen
- an int
, the total possible number of support
vectorskernel
- a Kernel
objectSVModel
structure containing the fitted modelNoSuchMethodException
- thrown when a particular method
cannot be foundInstantiationException
- thrown when an application tries
to create an instance of a class using the newInstance
method in class Class
, 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 constructorprotected double[] predictValues(SVModel model, double[][] attributeData) throws PredictiveModel.SumOfProbabilitiesNotOneException
predictValues
in class SupportVectorMachine
model
- a fitted SVModel
objectattributeData
- a double
matrix containing the
attribute (or predictor) datadouble
array containing the predictions for each
row in the input attribute dataPredictiveModel.SumOfProbabilitiesNotOneException
- the
sum of probabilities is not approximately oneCopyright © 2020 Rogue Wave Software. All rights reserved.