| Contents | Index |
SVMStruct = svmtrain(Training,Group)
SVMStruct = svmtrain(Training,Group,Name,Value)
SVMStruct = svmtrain(Training,Group) returns a structure, SVMStruct, containing information about the trained support vector machine (SVM) classifier.
SVMStruct = svmtrain(Training,Group,Name,Value) returns a structure with additional options specified by one or more Name,Value pair arguments.
To classify new data, use the result of training, SVMStruct, with the svmclassify function.
Specify optional comma-separated pairs of Name,Value arguments, where Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.
'autoscale' |
Boolean specifying whether svmtrain automatically centers the data points at their mean, and scales them to have unit standard deviation, before training. Default: true | ||||
'boxconstraint' |
Value of the box constraint C for the soft margin. C can be a scalar, or a vector of the same length as the training data. If C is a scalar, it is automatically rescaled by N/(2*N1) for the data points of group one and by N/(2*N2) for the data points of group two, where N1 is the number of elements in group one, N2 is the number of elements in group two, and N = N1 + N2. This rescaling is done to take into account unbalanced groups, that is cases where N1 and N2 have very different values. If C is an array, then each array element is taken as a box constraint for the data point with the same index. Default: 1 | ||||
'kernelcachelimit' |
Value that specifies the size of the kernel matrix cache for the SMO training method. The algorithm keeps a matrix with up to kernelcachelimit × kernelcachelimit double-precision, floating-point numbers in memory. Default: 5000 | ||||
'kernel_function' |
Kernel function svmtrain uses to map the training data into kernel space. The default kernel function is the dot product. The kernel function can be one of the following strings or a function handle:
Default: 'linear' | ||||
'kktviolationlevel' |
Value that specifies the fraction of variables allowed to violate the Karush-Kuhn-Tucker (KKT) conditions for the SMO training method. Set any value in [0,1). For example, if you set kktviolationlevel to 0.05, then 5% of the variables are allowed to violate the KKT conditions.
For more information on KKT conditions, see Cristianini and Shawe-Taylor [4]. Default: 0 | ||||
'method' |
Method used to find the separating hyperplane. Options are:
Default: SMO | ||||
'mlp_params' |
Parameters of the Multilayer Perceptron (mlp) kernel. The mlp kernel requires two parameters, [P1 P2]. The kernel K = tanh(P1*U*V' + P2), where P1 > 0 and P2 < 0. Default: [1 –1] | ||||
'options' |
Options structure for training.
| ||||
'polyorder' |
Order of the polynomial kernel. Default: 3 | ||||
'rbf_sigma' |
Scaling factor (sigma) in the radial basis function kernel. Default: 1 | ||||
'showplot' |
Boolean indicating whether to plot the grouped data and separating line. Creates a plot only when the data has two columns (features). Default: false | ||||
'tolkkt' |
Value that specifies the tolerance with which the Karush-Kuhn-Tucker (KKT) conditions are checked for the SMO training method. For a definition of KKT conditions, see Karush-Kuhn-Tucker (KKT) Conditions. Default: 1e-3 |
SVMStruct |
Structure containing information about the trained SVM classifier in the following fields:
|
The Karush-Kuhn-Tucker (KKT) conditions are analogous to the condition that the gradient must be zero at a minimum, modified to take constraints into account. The difference is that the KKT conditions hold for constrained problems. The KKT conditions use the auxiliary Lagrangian function:
![]()
Here f(x) is the objective function, g(x) is a vector of constraint functions g(x) ≤ 0, and h(x) is a vector of constraint functions h(x) = 0. The vector λ, which is the concatenation of λg and λh, is the Lagrange multiplier vector. Its length is the total number of constraints.
The KKT conditions are:

For more information, see Karush-Kuhn-Tucker conditions.
Find a line separating the Fisher iris data on versicolor and virginica species, according to the petal length and petal width measurements. These two species are in rows 51 and higher of the data set, and the petal length and width are the third and fourth columns.
load fisheriris xdata = meas(51:end,3:4); group = species(51:end); svmStruct = svmtrain(xdata,group,'showplot',true);

The svmtrain function uses an optimization method to identify support vectors si, weights αi, and bias b that are used to classify vectors x according to the following equation:
![]()
where k is a kernel function. In the case of a linear kernel, k is the dot product. If c ≥ 0, then x is classified as a member of the first group, otherwise it is classified as a member of the second group.
When you set 'Method' to 'QP', the svmtrain function operates on a data set containing N elements, and it creates an (N+1)-by-(N+1) matrix to find the separating hyperplane. This matrix needs at least 8*(n+1)^2 bytes of contiguous memory. If this size of contiguous memory is not available, the software displays an "out of memory" error message.
When you set 'Method' to 'SMO' (default), memory consumption is controlled by the kernelcachelimit option. The SMO algorithm stores only a submatrix of the kernel matrix, limited by the size specified by the kernelcachelimit option. However, if the number of data points exceeds the size specified by the kernelcachelimit option, the SMO algorithm slows down because it has to recalculate the kernel matrix elements.
When using svmtrain on large data sets, and you run out of memory or the optimization step is very time consuming, try either of the following:
Use a smaller number of samples and use cross-validation to test the performance of the classifier.
Set 'Method' to 'SMO', and set the kernelcachelimit option as large as your system permits.
[1] Kecman, V., Learning and Soft Computing, MIT Press, Cambridge, MA. 2001.
[2] Suykens, J.A.K., Van Gestel, T., De Brabanter, J., De Moor, B., and Vandewalle, J., Least Squares Support Vector Machines, World Scientific, Singapore, 2002.
[3] Scholkopf, B., and Smola, A.J., Learning with Kernels, MIT Press, Cambridge, MA. 2002.
[4] Cristianini, N., and Shawe-Taylor, J. (2000). An Introduction to Support Vector Machines and Other Kernel-based Learning Methods, First Edition (Cambridge: Cambridge University Press). http://www.support-vector.net/

See how to analyze, visualize, and model biological data and systems using MathWorks products.
Get free kit| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |