Class SVClassification

All Implemented Interfaces:
Serializable, Cloneable

public class SVClassification extends SupportVectorMachine implements Serializable, Cloneable
Specifies a support vector machine for classification (SVC).

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:
  • Constructor Details

    • SVClassification

      public SVClassification(double[][] xy, int responseColumnIndex, PredictiveModel.VariableType[] varType)
      Constructs a support vector machine for classification (SVC).
      Parameters:
      xy - a double matrix containing the training data and associated response values
      responseColumnIndex - an int, the column index of the response variable
      varType - a PredictiveModel.VariableType array of length equal to xy[0].length containing 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 - a double matrix containing the training data and associated response values
      responseColumnIndex - an int, the column index of the response variable
      varType - a PredictiveModel.VariableType array of length equal to xy[0].length containing the type of each variable
      k - a Kernel, the kernel function
    • SVClassification

      public SVClassification(SVClassification classModel)
      Copy constructor.
      Parameters:
      classModel -
  • Method Details

    • clone

      public SVClassification clone()
      Clones an SVClassification predictive model.
      Specified by:
      clone in class PredictiveModel
      Returns:
      a clone of the SVClassification predictive model
    • setClassPenaltyWeights

      public void setClassPenaltyWeights(int[] weightLabels, double[] weights)
      Sets the class penalty weights.
      Parameters:
      weightLabels - an int array containing the class labels to which the weights should be applied
      weights - 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.

    • getClassPenaltyWeights

      public double[] getClassPenaltyWeights()
      Returns the class weights.
      Returns:
      a double array containing the class weights
    • setConfiguration

      protected final void setConfiguration(PredictiveModel pm)
      Sets the configuration to that of the input PredictiveModel.

      Note that the input PredictiveModel object must be the same subclass of PredictiveModel as is this instance.

      Overrides:
      setConfiguration in class SupportVectorMachine
      Parameters:
      pm - an SVClassification instance
      Throws:
      PredictiveModel.CloneNotSupportedException - 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.

    • getClassWeightLabels

      public int[] getClassWeightLabels()
      Returns the weight labels array.
      Returns:
      an int array 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:
      optimize in class SupportVectorMachine
      Parameters:
      x - a DataNode matrix containing the attribute data
      y - a double array containing the response variable
      w - a double array containing the observation weights
      len - an int, the total possible number of support vectors
      kernel - a Kernel object
      Returns:
      an SVModel structure containing the fitted model
      Throws:
      NoSuchMethodException - thrown when a particular method cannot be found
      InstantiationException - 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 instantiated
      IllegalAccessException - 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 constructor
      InvocationTargetException - 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:
      predictValues in class SupportVectorMachine
      Parameters:
      model - a fitted SVModel object
      attributeData - a double matrix containing the attribute (or predictor) data
      Returns:
      a double array containing the predictions for each row in the input attribute data
      Throws:
      PredictiveModel.SumOfProbabilitiesNotOneException - the sum of probabilities is not approximately one