svm()

Description:

The external library function solves binary classification problems and regression problems using SVM algorithm.

Syntax:

svm(X,Y,param)

Use parameter param to train training dataset X, which is an independent variable, and training dataset Y, which is a dependent variable, and return training result – model R

svm(R,Xpre)

Predict data of scoring set XPre based on model R and return prediction result

svm(X,Y,param,XPre)

Connect training and prediction; input training data X, the independent variable, training data Y, the dependent variable, modeling parameter param and scoring set XPre to perform the linkage model training and prediction, and return prediction result

Note:

Parameter param contains five types of SVM model parameter sets. It is important that you set the parameter for specifying the desired model.

Parameters:

X

A sequence representing the training set independent variable

Y

A sequence representing the training set objective variable

param

A sequence of SVM model parameters

R

A sequence, which is result returned by syntax svm(X,Y,param)

XPre

A sequence representing the scoring data set

There are 13 parameters in parameter param. They will be read in order during computation. Here are brief introductions of them by their positions:

Position

Param description

Value

Value description

Pos 1

svm_type: An integer representing the available model type; default value is 0

0

C-SVC

1

nu-SVC

2

one-class SVM

3

epsilon-SVR, one of the regression algorithms

4

nu-SVR, one of the regression algorithms

Pos 2

kernel_type: An integer representing a kernel function; default value is 2

0

linear: u'*v – linear kernel

1

polynomial: (gamma*u'*v + coef0)^degree – polynomial kernel

2

radial basis function: exp(-gamma*|u-v|^2) – Gaussian kernel /RBF kernel

3

sigmoid: tanh(gamma*u'*v + coef0) – sigmoid kernel

Pos 3

degree: An integer representing degree fo polynomial kernel (‘poly’), whose default value is 3; ignore this parameter for the other kernels

Pos 4

cache_size: A floating-point number for setting the kernel cache size (unit:MB); default value is 100

Pos 5

eps: A floating-point number representing the error term that invalidates the defined error range; default value is 0.001

Pos 6

C: A floating-point number representing the regularization parameter C, which is the penalty parameter in C-SVC, ε-SVR and nu-SVR; default value is 1

Pos 7

gamm: A floating-point number representing the gamma coefficient in kernel functions poly, RBF and sgmoid; default value is 1 or the related characteristic number

Pos 8

coef0: A floating-point number representing coef0 in kernel functions poly and sigmoid; default value is 0

Pos 9

nu: A floating-point number representing the upper bound of training error or lower bound of support vector, and set for nu-SVC, one-class-SVM and nu-SVR; its value range is (0,1) and default is 0.5

Pos 10

p: A floating-point number representing epsilon that is set in epsilon-SVR loss function; default value is 0.1

Pos 11

nr_weight: A floating-point number for tuning penalty weight in certain classes within C_SVC; default value is 1; if there is no need to modify the penalty in any classes, just set its value as 0

Pos 12

shrinking: Boolean value 0 or 1 that denotes whether or not to use the shrinking heuristics; default value is 1

Pos 13

probability: Boolean value 0 or 1 that denotes whether or not to calculate probability estimate for SVC; default value is 0

Return value:

A sequence

Example:

 

A

 

1

[[17.6,17.7,17.7,17.7],[17.7,17.7,17.7,17.8],[17.7,17.7,17.8,17.8],[17.7,17.8,17.8,17.9],[17.8,17.8,17.9,18],[17.8,17.9,18,18.1],[17.9,18,18.1,18.2],[18,18.1,18.2,18.4],[18.1,18.2,18.4,18.6],[18.2,18.4,18.6,18.7],[18.4,18.6,18.7,18.9],[18.6,18.7,18.9,19.1]]

Training set independent variable X

2

[17.8,17.8,17.9,18,18.1,18.2,18.4,18.6,18.7,18.9,19.1,19.3]

Training set independent variable Y

3

[3,0,3,100,0.00001,1,0.25,0,0.5,0.1,1,1,1]

Set parameter param

4

[[18.7,18.9,19.1,19.3],[18.9,19.1,19.3,19.6],[19.1,19.3,19.6,19.9],[19.3,19.6,19.9,20.2],[19.6,19.9,20.2,20.6],[19.9,20.2,20.6,21],[20.2,20.6,21,21.5]]

Scoring set XPre

5

=svm(A1,A2,A3)


Train the training set of data according to parameters set in A3 and return training result R; member values of R in order are: support vector coefficient in the decision function, label for each class, number of classes, total number of support vectors, number of support vectors in each class, constant in the decision function, support vector and parameter param for training

6

=svm(A5,A4)

Perform prediction on the scoring set according to training result R and return prediction result


7

=svm(A1,A2,A3,A4)


Train the training set of data according to parameters set in A3, perform prediction on the scoring set, and return prediction result