| Bioinformatics Toolbox | |
Train a support vector machine classifier
SVMStruct = svmtrain(Training, group)
svmtrain(...,'kernel_function',kfun)
svmtrain(..., 'polyorder', order)
svmtrain(...,'mlp_params',[p1 p2])
svmtrain(...,'method',method)
svmtrain(..., 'quadprog_opts',options)
svmtrain(..., 'showplot',true)
SVMStruct = svmtrain(Training, group) trains a support vector machine classifier using data Training taken from two groups given by group. SVMStruct contains information about the trained classifier that is used by svmclassify for classification. group is a column vector of values, of the same length as Training, that defines two groups. Each element of group specifies the group to which the corresponding row of Training belongs. group can be a numeric vector, a string array, or a cell array of strings. svmtrain treats NaNs or empty strings in group as missing values, and ignores the corresponding rows of Training.
svmtrain(...,'kernel_function',kfun) specifies the kernel function kfun that is used to map the training data into kernel space. The default kernel function is the dot product. kfun can be one of the following strings or a function handle:
| 'linear' | Linear kernel or dot product |
| 'quadratic' | Quadratic kernel |
| 'polynomial' | Polynomial kernel (default order 3) |
| 'rbf' | Gaussian radial basis function kernel |
| 'mlp' | Multilayer perceptron kernel (default scale 1) |
| Function handle | A handle to a kernel function specified using @, for example @kfun, or an anonymous function |
A kernel function must be of the form
function K = kfun(U, V)
The returned value K is a matrix of size m-by-n, where U and V have m and n rows respectively. If kfun is parameterized, you can use anonymous functions to capture the problem-dependent parameters. For example, suppose that your kernel function is
function k = kfun(u,v,p1,p2) k = tanh(p1*(u*v')+p2);
You can set values for p1 and p2 and then use an anonymous function as follows:
@(u,v) kfun(u,v,p1,p2)
svmtrain(..., 'polyorder', order)enables you to specify the order of a polynomial kernel. The default order is 3.
svmtrain(...,'mlp_params',[p1 p2])enables you to specify the parameters of the multilayer perceptron (mlp) kernel. The mlp kernel requires two parameters, p1 and p2, where K = tanh(p1*U*V' + p2), p1 > 0, and p2 < 0. Default values are p1 = 1 and p2 = -1.
svmtrain(...,'method',method)enables you to specify the method used to find the separating hyperplane. The options are
| 'QP' | Quadratic programming (requires the Optimization Toolbox) |
| 'LS' | Least-squares method |
Note If you installed the Optimization Toolbox, the 'QP' method is the default. If not, the only available method is 'LS'. |
svmtrain(..., 'quadprog_opts',options)enables you to pass an options structure, created using optimset, to the Optimization Toolbox function quadprog when using the 'QP' method. See the optimset reference page for more details.
svmtrain(..., 'showplot',true), when used with two-dimensional data, creates a plot of the grouped data and plots the separating line for the classifier.
Load sample data
load fisheriris X = [meas(:,1), meas(:,2)];
Extract the Setosa class
groups = ismember(species,'setosa');
Randomly select training and test sets
[train, test] = crossvalind('holdOut',groups);Use a linear support vector machine classifier
svmStruct = svmtrain(X(train,:),groups(train),'showplot',true); classes = svmclassify(svmStruct,X(test,:),'showplot',true);
Statistical Toolbox functions classify, knnclassify, quadprog, svmclassify
| svmclassify |
© 1994-2005 The MathWorks, Inc.