public abstract class SupportVectorMachine extends PredictiveModel
Support vector machines are machine learning algorithms for classification,
regression, and the so-called one class problem. This package contains
SVClassification
, SVRegression
, and
SVOneClass
for each of these problems, respectively. Each
formulation uses a kernel based optimization to find support vectors that
optimally separate clouds of high dimensional data for the purpose of making
predictions. SupportVectorMachine
and all of the classes in this
package are based on the LIBSVM
package of Chang, Chih-Chung;
Lin, Chih-Jen (2011).
Modifier and Type | Class and Description |
---|---|
static class |
SupportVectorMachine.CloneNotSupportedException
Wraps the
java.lang.CloneNotSupportedException to indicate
that the clone method in class Object has been
called to clone an object, but that the object's class does not implement
the Cloneable interface. |
static class |
SupportVectorMachine.ReflectiveOperationException
Class that wraps exceptions thrown by reflective operations in core
reflection.
|
PredictiveModel.PredictiveModelException, PredictiveModel.StateChangeException, PredictiveModel.SumOfProbabilitiesNotOneException, PredictiveModel.VariableType
Constructor and Description |
---|
SupportVectorMachine(double[][] xy,
int responseColumnIndex,
PredictiveModel.VariableType[] varType)
Constructs a support vector machine for a single response variable and
multiple predictor variables.
|
SupportVectorMachine(double[][] xy,
int responseColumnIndex,
PredictiveModel.VariableType[] varType,
Kernel k)
Constructs a support vector machine for a single response variable and
multiple predictor variables.
|
Modifier and Type | Method and Description |
---|---|
void |
fitModel()
Fits the model to the training data, i.e, trains the support vector
machine.
|
double |
getConvergenceTolerance()
Returns the convergence tolerance.
|
protected Kernel |
getKernel()
Returns the kernel object being used in the optimization.
|
double[] |
getKernelParameters()
Returns the kernel parameters.
|
protected SVModel |
getModel()
Returns the model object.
|
double |
getNuParameter()
Returns the value of the parameter.
|
double |
getRegularizationParameter()
Returns the value of the regularization parameter, C.
|
double |
getWorkingArraySize()
Returns the setting for the work array size.
|
boolean |
isNuFormulation()
Returns the boolean to perform the
-formulation of the optimization problem.
|
boolean |
isProbability()
Returns the boolean to calculate probability estimates.
|
boolean |
isShrinking()
Returns the boolean to perform shrinking during optimization.
|
protected abstract SVModel |
optimize(DataNode[][] x,
double[] y,
double[] w,
int len,
Kernel kernel)
Abstract method to perform the support vector machine optimization.
|
double[] |
predict()
Returns the predicted values on the training data, i.e., returns the
fitted values.
|
double[] |
predict(double[][] testData)
Returns the predicted values on the input test data.
|
protected abstract double[] |
predictValues(SVModel model,
double[][] attributeData)
Abstract method for generating the predicted values using the fitted
support vector machine model.
|
protected void |
setConfiguration(PredictiveModel pm)
Sets the configuration of
PredictiveModel to that of the
input model. |
void |
setConvergenceTolerance(double eps)
Sets the convergence tolerance.
|
void |
setKernel(Kernel kernel)
Sets the kernel to be used in the optimization.
|
void |
setKernelParameters(double[] kParams)
Sets the kernel parameters.
|
void |
setNuFormulation(boolean nuFormulation)
Sets the boolean to perform the -formulation of
the optimization problem.
|
void |
setNuParameter(double nu)
Sets the value of in the
-formulation of the optimization problem.
|
void |
setProbability(boolean probability)
Sets the boolean to calculate probability estimates.
|
void |
setRegularizationParameter(double C)
Sets the regularization parameter, C.
|
void |
setShrinking(boolean shrinking)
Sets the boolean to perform shrinking during optimization.
|
void |
setWorkArraySize(double workSize)
Sets the work array size.
|
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, isMustFitModel, isUserFixedNClasses, predict, setClassCounts, setClassLabels, setClassProbabilities, setCostMatrix, setMaxNumberOfCategories, setMaxNumberOfIterations, setMustFitModel, setNumberOfClasses, setPredictorIndex, setPredictorTypes, setPrintLevel, setPriorProbabilities, setRandomObject, setResponseColumnIndex, setTrainingData, setVariableType, setWeights
public SupportVectorMachine(double[][] xy, int responseColumnIndex, PredictiveModel.VariableType[] varType)
xy
- a double
matrix containing the training data and
associated response valuesresponseColumnIndex
- an int
specifying the column
index of the response variablevarType
- a PredictiveModel.VariableType
array of
length equal to xy[0].length
containing the type of each
variablepublic SupportVectorMachine(double[][] xy, int responseColumnIndex, PredictiveModel.VariableType[] varType, Kernel k) throws CloneNotSupportedException
xy
- a double
matrix containing the training data and
associated response valuesresponseColumnIndex
- an int
specifying 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 functionCloneNotSupportedException
- thrown to indicate that the
clone
method in class Object
has been called
to clone an object, but that the object's class does not implement the
Cloneable
interfacepublic void fitModel() throws PredictiveModel.PredictiveModelException
fitModel
in class PredictiveModel
PredictiveModel.PredictiveModelException
- an exception has
occurred in the com.imsl.datamining.PredictiveModel. Superclass
exceptions should be considered such as
com.imsl.datamining.PredictiveModel.StateChangeException,
com.imsl.datamining.PredictiveModel.SumOfProbabilitiesNotOneException,
and
com.imsl.datamining.supportvectormachine.SupportVectorMachine.ReflectiveOperationException.public double getConvergenceTolerance()
double
, the tolerance valueprotected Kernel getKernel()
Kernel
objectpublic double[] getKernelParameters()
Kernel
class for specifications of the parameters.double
array containing the kernel parameter
valuesprotected SVModel getModel()
SVModel
objectpublic double getNuParameter()
double
, the current value of the
parameterpublic double getRegularizationParameter()
double
, the value of the regularization parameterpublic double getWorkingArraySize()
double
, the number of megabytes allocated to the
work array used in the decomposition methodpublic boolean isNuFormulation()
true
, the
-formulation of the optimization problem is
solved. When false
, the standard or default formulation is
solved.boolean
, the current value of the flagpublic boolean isProbability()
boolean
, indicating whether or not probability
estimates for each class level should be computedpublic boolean isShrinking()
true
, the optimization performs shrinking.boolean
, the value of the shrinking
flagprotected abstract SVModel optimize(DataNode[][] x, double[] y, double[] w, int len, Kernel kernel) throws NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException
x
- a DataNode
matrix containing the attribute datay
- a double
array containing the response variablelen
- an int
, the total possible number of support
vectorsw
- a double
array containing the observation weightskernel
- an 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 constructorpublic double[] predict() throws PredictiveModel.SumOfProbabilitiesNotOneException
predict
in class PredictiveModel
double
array containing the fitted values on the
training dataSumOfProbabilitiesNotOneException
- the sum of probabilities is not
approximately onePredictiveModel.SumOfProbabilitiesNotOneException
public double[] predict(double[][] testData) throws PredictiveModel.SumOfProbabilitiesNotOneException
predict
in class PredictiveModel
testData
- a double
matrix containing test data
Note: testData
must have the same number of columns
as xy
and the columns must be in the same arrangement as in
xy
.
double
array containing the predicted valuesSumOfProbabilitiesNotOneException
- the sum of probabilities is not
approximately onePredictiveModel.SumOfProbabilitiesNotOneException
protected abstract double[] predictValues(SVModel model, double[][] attributeData) throws PredictiveModel.SumOfProbabilitiesNotOneException
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 oneprotected void setConfiguration(PredictiveModel pm) throws SupportVectorMachine.CloneNotSupportedException
PredictiveModel
to that of the
input model.
Note that the input PredictiveModel
object must be the same
subclass of PredictiveModel
as is this instance.
setConfiguration
in class PredictiveModel
pm
- a PredictiveModel
object which is to have its
attributes duplicated in this 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.
SupportVectorMachine.CloneNotSupportedException
public void setConvergenceTolerance(double eps)
eps
- a double
, the tolerance value
Default: eps
=0.001
public void setKernel(Kernel kernel)
See the class Kernel
for details.
kernel
- an instance of class Kernel
Default: kernel=RadialBasisKernel
public void setKernelParameters(double[] kParams)
Kernel
class for specifications of the parameters.kParams
- a double
array containing the kernel
parameter valuespublic void setNuFormulation(boolean nuFormulation)
true
, the
-formulation of the optimization problem is
solved. When false
, the standard formulation is solved.
The -support vector classification (-SVC) algorithm presents a new parameter which acts as an upper bound on the fraction of training errors and a lower bound on the fraction of support vectors.
The primal optimization problem for the binary variable is
Similar to -SVC, in -support vector regression (-SVR) the parameter controls the number of support vectors. The -SVR primal problem is
nuFormulation
- a boolean
, giving the value for the
flag
Default: nuFormulation
=false
public void setNuParameter(double nu)
nu
- a double
in (0,1], the
parameter
Default: nu
=0.5
public void setProbability(boolean probability)
In classification problems, when the flag is true
, class
probabilities are estimated during the training procedure. For regression
problems, when the flag is true
, distributional parameters
will be estimated that allow probability inferences for the response
variable. When false
, probability information is not
calculated.
probability
- a boolean
, indicating whether or not to
calculate probability estimates
Default: probability
=false
public void setRegularizationParameter(double C)
C
- a double
, greater than 0.0
Default: C
=1.0
public void setShrinking(boolean shrinking)
The shrinking technique tries to identify and remove some bounded elements during the application of the SMO (sequential minimal optimization) algorithm, so that a smaller optimization problem is solved.
shrinking
- a boolean
, indicating whether or not
shrinking should be performed during the optimization algorithm
Default: shrinking
=true
public void setWorkArraySize(double workSize)
A larger work array size can reduce the computational time of the decomposition method.
workSize
- a double
, the number of megabytes allocated
for the array used during the decomposition method. workSize
must be greater than 0.
Default: workSize
= 100.0
Copyright © 1970-2016 Rogue Wave Software
Built May 19 2016.