IMSL C Stat Library
support_vector_classification
Classifies unknown patterns using a previously trained Support Vector Machines (SVM) model computed by imsls_f_support_vector_trainer.
Synopsis
#include <imsls.h>
float *imsls_f_support_vector_classification ( Imsls_f_svm_model *svm_classifier, int  n_patterns, float x[], …, 0)
The type double function is imsls_d_support_vector_classification.
Required Arguments
Imsls_f_ svm_model *svm_classifier (Input)
Pointer to a structure of type Imsls_f_svm_model from imsls_f_support_vector_trainer.
int n_patterns (Input)
Number of patterns to classify.
float x[] (Input)
An array of length n_patterns by n_attributes containing the data matrix where n_attributes is the number of attributes as specified in imsls_f_support_vector_trainer.
Return Value
Pointer to an array of length n_patterns containing the predicted classification associated with each input pattern for a classification model, or the calculated function value for a regression model. If classification is unsuccessful, NULL is returned. To release this space, use imsls_free.
Synopsis with Optional Arguments
#include <imsls.h>
float *imsls_f_support_vector_classification (Imsls_f_svm_model  *svm_classifier, int n_patterns, float  x[],
IMSLS_SVM_KERNEL_PRECOMPUTED, float kernel_values[],
IMSLS_PREDICTED_CLASS_PROB, float **pred_class_prob,
IMSLS_PREDICTED_CLASS_PROB_USER, float pred_class_prob[],
IMSLS_SVR_PROBABILITY, float  *svr_probability,
IMSLS_CLASS_ERROR, float classification[], int **class_errors,
IMSLS_CLASS_ERROR_USER, float *classification, int class_errors[],
IMSLS_DECISION_VALUES, int i, float **dec_values,
IMSLS_DECISION_VALUES_USER, int i, float dec_values[],
IMSLS_RETURN_USER, float predicted_labels[],
0)
Optional Arguments
IMSLS_SVM_KERNEL_PRECOMPUTED, float kernel_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.
float kernel_values[] (Input)
An array of length n_patterns by n_patterns containing the precomputed kernel function values. Assume there are L testing 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_PREDICTED_CLASS_PROB, float **pred_class_prob (Output)
The address of a pointer to an array of length n_patterns by n_classes, where n_classes is the number of target classifications. The values in the i-th row are the predicted classification probabilities associated with the target classes. pred_class_prob[i*n_classes+j] is the estimated probability that the i-th pattern belongs to the j-th target class.
For regression and one-class SVMs, the array pred_class_prob is NULL.
To release this space, use imsls_free.
IMSLS_PREDICTED_CLASS_PROB_USER, float pred_class_prob[] (Output)
Storage for array pred_class_prob is provided by the user. See IMSLS_PREDICTED_CLASS_PROB for a description.
IMSLS_SVR_PROBABILITY, float *svr_probability (Output)
For a regression model with probability information, this option outputs a value σ > 0. For the test data, we consider the probability model as
target value = predicted value + z
where z is distributed according to Laplace with zero-mean density function p(x) = e|x|/σ/2σ . svr_probability contains σ on output. If the model is not for SVR or does not contain the required probability information, 0 is returned.
IMSLS_CLASS_ERROR, float classification[], int **class_errors (Output)
Returns classification error counts.
float classification[] (Input)
An array of length n_patterns containing the known classifications for each of the patterns.
int **class_errors (Output)
The address of a pointer to an array of length (n_classes+1) by 2 containing the number of classification errors and the number of non-missing classifications for each target classification, plus the overall totals for these errors. For i < n_classes, the i-th row contains the number of classification errors for the i-th class and the number of patterns with non-missing classifications for that class. The last row contains the number of classification errors totaled over all target classifications, and the total number of patterns with non-missing target classifications. To release this space, use imsls_free.
IMSLS_CLASS_ERROR_USER, float classification[], int class_errors[] (Output)
Storage for class_errors is provided by the user. See IMSLS_CLASS_ERROR for a description.
IMSLS_DECISION_VALUES, int i, float **dec_values (Output)
Gives decision values on row i of data matrix x. The decision values are used to predict the target classification value. For binary class problems, decision values are signed values used to determine which side of the decision boundary the observation in question lays. Recall that SVM combines multiple binary classifiers for multi-class classification. The magnitudes of the decision values are essentially meaningless as only the sign is used to determine whether the point is more likely to belong to class[i] versus class[j] (a positive value) or less likely to belong to class[i] versus class[j] (a negative value). See the Description section for more on how the decision values are used to predict the target classification value.
For a classification model with n_classes classes, this function gives n_classes*(n_classes-1)/2 decision values in the array dec_values. The order is class[0] vs. class[1], , class[0] vs. class[n_classes-1], class[1] vs. class[2], , class[1] vs. class[n_classes-1], , class[n_classes-2] vs. class[n_classes-1], where class contains the target classification values.
For a regression model, only 1 value is returned. dec_values[0] is the function value of row i of x calculated using the model. For a one-class model, dec_values[0] is the decision value of row i of x. To release this space, use imsls_free
IMSLS_DECISION_VALUES_USER, int i, float dec_values[] (Output)
Storage for array dec_values is provided by the user. See IMSLS_DECISION_VALUES for a description.
IMSLS_RETURN_USER, float predicted_labels[] (Output)
Storage for the return values is provided by the user in array predicted_labels. predicted_labels must be at least of length n_patterns.
Description
Function imsls_f_support_vector_classification estimates classification probabilities from a previously trained SVM model. This function does classification or regression on a test vector x using the SVM model output from imsls_f_support_vector_trainer. For a classification model, the predicted class for x is returned. For a regression model, the function value of x calculated using the model is returned. For a one-class model, +1 or -1 is returned signifying that the observation belongs to (+1) or does not belong to (‑1) the expected class. The predicted classification returned by this function is the class with the largest estimated classification probability. The classification probability estimates for each pattern can be obtained using the optional argument IMSLS_PREDICTED_CLASS_PROB.
The decision values which are returned through the use of optional argument IMSLS_DECISION_VALUES are used to cast votes for the target classification value. Only the sign of the decision value is used in casting votes. For a decision value for class[i] versus class[j], a positive value is interpreted as class[i] being more likely than class[j], so class[i] would get a vote. A negative value is interpreted as class[i] being less likely than class[j], so class[j] would get a vote. The votes along a row of decision values are tallied to elect the class with the most votes as the target classification value. In case of a tie, the first class encountered with the highest number of votes in a row of decision values is the predicted class for that row.
Function imsls_f_support_vector_classification 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
See Examples in imsls_f_support_vector_trainer.
Warning Errors
IMSLS_INADEQUATE_MODEL
The model used contains inadequate information to compute the requested probability.