The type double function is imsls_d_support_vector_trainer.
Required Arguments
intn_patterns (Input) Number of training patterns.
intn_classes (Input) Number of unique target classification values.
intn_attributes (Input) Number of attributes.
floatclassification[] (Input) Array of length n_patterns containing the target classification values for each of the training patterns.
float x[] (Input) Array of length n_patterns by n_attributes containing the training data matrix.
Return Value
A pointer to a structure of type Imsls_f_svm_model containing the trained support vector classifier model. If training is unsuccessful, NULL is returned. To release this space, use imsls_f_svm_classifier_free.
IMSLS_SVM_C_SVC_TYPE, floatC, intnr_weight, floatweight_class[], floatweight[] (Input) Specifies that the C-support vector classification (C-SVC) algorithm is to be used to create the classification model. This is the default type of SVM used.
floatC (Input) The regularization parameter. C must be greater than 0. By default, the penalty parameters are set to the regularization parameter C. The penalty parameters can be changed by scaling C by the values specified in weight below.
intnr_weight (Input) The number of elements in weight and weight_class used to change the penalty parameters.
floatweight_class[] (Input) An array of length nr_weight containing the target classification values that are to be weighted.
floatweight[] (Input) An array of length nr_weight containing the weights corresponding to the target classification values in weight_class to be used to change the penalty parameters.
Default: C-SVC is the default SVM type used with C = 5.0, nr_weight = 0, weight_class = NULL, and weight = NULL.
or
IMSLS_SVM_NU_SVC_TYPE, floatnu (Input) Specifies that the ν-support vector classification (ν-SVC) algorithm is to be used to create the classification model.
floatnu (Input) The parameter nu controls the number of support vectors and nu∈ (0,1].
or
IMSLS_SVM_ONE_CLASS_TYPE, floatnu (Input) Specifies that the distribution estimation (one-class SVM) algorithm is to be used to create the classification model.
floatnu (Input) The parameter nu controls the number of support vectors and nu∈ (0,1].
or
IMSLS_SVM_EPSILON_SVR_TYPE, floatC, float p (Input) Specifies that the ɛ-support vector regression (ɛ-SVM) algorithm is to be used to create the classification model.
floatC (Input) The regularization parameter. C must be greater than 0.
floatp (Input) The insensitivity band parameter p must be positive.
or
IMSLS_SVM_NU_SVR_TYPE, floatC, floatnu (Input) Specifies that the ν-support vector regression (ν-SVR) algorithm is to be used to create the classification model.
floatC (Input) The regularization parameter. C must be greater than 0.
floatnu (Input) The parameter nu controls the number of support vectors and nu∈ (0,1].
IMSLS_SVM_WORK_ARRAY_SIZE, floatwork_size (Input) This work array size argument sets the number of megabytes allocated for the work array used during the decomposition method. A larger work array size can reduce the computational time of the decomposition method. Default: work_size = 1.0.
IMSLS_SVM_EPSILON, floatepsilon (Input) The absolute accuracy tolerance for termination criterion. The algorithm uses the SMO algorithm in solving the optimization problem. When the Lagrange multipliers used in the SMO algorithm satisfy the Karush-Kuhn-Tucker (KKT) conditions within epsilon, convergence is assumed. Default: epsilon = 0.001.
IMSLS_SVM_NO_SHRINKING, (Input) Use of this argument specifies that the shrinking technique is not to be used in the SMO algorithm. The shrinking technique tries to identify and remove some bounded elements during the application of the SMO algorithm, so a smaller optimization problem is solved. Default: Shrinking is performed.
IMSLS_SVM_TRAIN_ESTIMATE_PROB, (Input) Instructs the trainer to include information in the resultant classifier model to enable you to obtain probability estimates when invoking imsls_f_support_vector_classification. Default: Information necessary to obtain probability estimates is not included in the model.
IMSLS_SVM_KERNEL_LINEAR, (Input) This argument specifies that the inner-product kernel type
K(xi , xj) = xiTxj
is to be used. This kernel type is best used when the relation between the target classification values and attributes is linear or when the number of attributes is large (for example, 1000 attributes).
or
IMSLS_SVM_KERNEL_POLYNOMIAL, intdegree, floatgamma, floatcoef0 (Input) This argument specifies that the polynomial kernel type
K(xi , xj) = ( xiTxj + r)d
is to be used. Use this argument when the data are not linearly separable.
intdegree (Input) Parameter degree specifies the order of the polynomial kernel. degree = d in the equation above.
floatgamma (Input) Parameter gamma must be greater than 0. gamma = in the equation above.
floatcoef0 (Input) Parameter coef0 corresponds to r in the equation above.
or
IMSLS_SVM_KERNEL_RADIAL_BASIS, floatgamma (Input) This argument specifies that the radial basis function kernel type
K(xi , xj) = exp (-∥xi - xj∥2)
is to be used. Use this kernel type when the relation between the class labels and attributes is nonlinear, although it can also be used when the relation between the target classification values and attributes is linear. This kernel type exhibits fewer numerical difficulties. If no kernel type is specified, this is the kernel type used.
floatgamma (Input) Parameter gamma must be greater than 0. gamma = in the equation above.
or
IMSLS_SVM_KERNEL_SIGMOID, floatgamma, floatcoef0 (Input) This argument specifies that the sigmoid kernel type
K(xi , xj) = tanh( xiTxj + r)
is to be used.
floatgamma (Input) Parameter gamma = in the equation above.
floatcoef0 (Input) Parameter coef0 corresponds to r in the equation above.
or
IMSLS_SVM_KERNEL_PRECOMPUTED, floatkernel_values[] (Input) Use of this argument indicates that the kernel function values have been precomputed for the training and testing data sets. If IMSLS_SVM_KERNEL_PRECOMPUTED is used, the required argument x is ignored.
floatkernel_values[] (Input) An array of length n_patterns by n_patterns containing the precomputed kernel function values. Assume there are L training instances x1, x2, …, xL and let K(x,y) be the kernel function value of two instances x and y. Row i of the testing or training data set would be represented by K(xi,x1) K(xi,x2)…K(xi,xL). All kernel function values, including zeros, must be provided.
IMSLS_SVM_CROSS_VALIDATION, intn_folds, float**target, float*result (Input/Output) Conducts cross validation on n_folds folds of the data. imsls_f_random_uniform_discrete is used during the cross validation step. See the Description section for more information on cross validation. See the Usage Notes in Chapter 12, “Random Number Generation” for instructions on setting the seed to the random number generator if different seeds are desired.
intn_folds (Input) The number of folds of the data to be used in cross validation. n_folds must be greater than 1 and less than n_patterns.
float**target (Output) The address of a pointer to an array of length n_patterns containing the predicted labels
float*result (Output) If the SVM type used is SVR, result contains the mean squared error. For all other SVM types result contains the accuracy percentage. Default: Cross validation is not performed.
IMSLS_SVM_CROSS_VALIDATION_USER, intn_folds, floattarget[], float*result (Input/Output) Storage for array target is provided by the user. See IMSLS_SVM_CROSS_VALIDATION for a description.
Description
Function imsls_f_support_vector_trainer trains an SVM classifier for classifying data into one of n_classes target classes. There are several SVM formulations that are supported through the optional arguments for classification, regression, and distribution estimation. The C-support vector classification (C-SVC) is the fundamental algorithm for the SVM optimization problem and its primal form is given as
Where (xi, yi) are the instance-label pairs for a given training set, where l is the number of training examples, and xi∈Rn and yi∈ {1,-1}. ξi are the slack variables in optimization and is 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 used and can be controlled through the use of the IMSLS_SVM_C_SVC_TYPE optional argument.
The ν-support vector classification (ν-SVC) algorithm presents a new parameter ν∈ (0,1] which acts as an upper bound on the fraction of training errors and a lower bound on the fraction of support vectors. The use of this algorithm is triggered through the use of the IMSLS_SVM_NU_SVC_TYPE optional arguement. The primal optimization problem for the binary variable y∈ {1,-1} is
The one-class SVM algorithm estimates the support of a high-dimensional distribution without any class information. Control of this algorithm is through the use of the IMSLS_SVM_ONE_CLASS_TYPE optional argument. The primal problem of one-class SVM is
If zi is the target output and given the parameters C > 0, ɛ > 0, the standard form of ɛ-support vector regression (ɛ-SVR) is
where the two slack variables ξi and ξi* are introduced, one for exceeding the target value by more than ɛ and the other for being more than ɛ below the target. The use of this algorithm is triggered through the use of the IMSLS_SVM_EPSILON_SVR_TYPE optional argument.
Similar to ν-SVC, in ν-support vector regression (ν-SVR) the parameter ν∈ (0,1] controls the number of support vectors. Use IMSLS_SVM_NU_SVR_TYPE to trigger this algorithm. The ν-SVR primal problem is
The decomposition method used to solve the dual formulation of these primal problems is an SMO-type (sequential minimal optimization) decomposition method proposed by Fan et. al. (2005).
The IMSLS_SVM_CROSS_VALIDATION optional argument allows one to estimate how accurately the resulting training model will perform in practice. The cross validation technique partitions the training data into n_folds complementary subsets. Each of the subsets is subsequently used in training and validated against the remaining subsets. The validation results of the rounds are then averaged. The result is usually a good indicator of how the trained model will perform on unclassified data.
Function imsls_f_support_vector_trainer is based on LIBSVM, Copyright (c) 2000-2013, with permission from the authors, Chih-Chung Chang and Chih-Jen Lin, with the following disclaimer:
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Examples
Example 1
In this example, we use a subset of the Fisher Iris data to train the classifier. The default values of imsls_f_support_vector_trainer are used in the training. The resultant classifier model, stored in svm_classifier, is then used as input to imsls_f_support_vector_classification to classify all of the patterns in the Fisher Iris data set. Results of the classification are then printed. In the Fisher Iris data set, the first column is the target classification value, 1=Setosa, 2=Versicolour, and 3=Virginica. Columns 2 through 5 contain the attributes sepal length, sepal width, petal length, and petal width.
#include <imsls.h>
#include <stdio.h>
int main()
{
int i, ii, j, jj, k, kk, method=1;
int n_patterns =150; /* 150 total patterns */
int n_patterns_train =30; /* 30 training patterns */
int n_attributes =4; /* four attributes */
int n_classes =3; /* three classification categories */
In this example we use a subset of the Fisher Iris data to train the classifier and use the cross-validation option with various combinations of C and gamma to find a combination which yields the best results on the training data. The best combination of C and gamma are then used to get the classification model, stored in svm_classifier. This model is then used as input to imsls_f_support_vector_classification to classify all of the patterns in the Fisher Iris data set. Results of the classification are then printed.
#include <imsls.h>
#include <stdio.h>
int main()
{
int i, ii, j, jj, k, kk, method=1;
int n_patterns_train =30; /* 30 training patterns */
int n_patterns =150; /* 150 total patterns */
int n_attributes =4; /* four attributes */
int n_classes =3; /* three classification categories */
One thousand uniform deviates from a uniform distribution are used in the training data set of this example. IMSLS_SVM_ONE_CLASS_TYPE is used to produce the model during training. A test data set of one hundred uniform deviates is produced and contaminated with ten normal deviates. imsls_f_support_vector_classification is then called in an attempt to pick out the contaminated data in the test data set. The suspect observations are printed.
#include <stdio.h>
#include <imsls.h>
#define N_PATTERNS_TRAIN 1000
#define N_PATTERNS_TEST 100
#define N_PATTERNS_TEN 10
#define N_CLASSES 1
#define N_ATTRIBUTES 1
int main()
{
int i;
float *target=NULL;
float classification_train[N_PATTERNS_TRAIN];
float classification_test[N_PATTERNS_TEST];
float *x_train;
float *x_test;
float *x_test_contaminant;
Imsls_f_svm_model *svm_classifier=NULL;
/* Create the training set from a uniform distribution */
printf("The %d-th observation may not to belong to the",i);
printf(" target distribution.\n");
}
}
if (svm_classifier) imsls_f_svm_classifier_free(svm_classifier);
if (target) imsls_free(target);
if (x_train) imsls_free(x_train);
if (x_test) imsls_free(x_test);
if (x_test_contaminant) imsls_free(x_test_contaminant);
}
Output
Classification Results
The 0-th observation may not belong to the target distribution.
The 20-th observation may not belong to the target distribution.
The 30-th observation may not belong to the target distribution.
The 40-th observation may not belong to the target distribution.
The 60-th observation may not belong to the target distribution.
The 70-th observation may not belong to the target distribution.
Example 4
This example uses IMSLS_SVM_NU_SVR_TYPE to create a regression model which is used by imsls_f_support_vector_classification in an attempt to predict values in the test data set. The predicted values are printed.