支持向量机matlab实现源代码知识讲解

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

支持向量机m a t l a b 实现源代码

edit svmtrain

>>edit svmclassify

>>edit svmpredict

function [svm_struct, svIndex] = svmtrain(training, groupnames, varargin)

%SVMTRAIN trains a support vector machine classifier

%

% 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 the corresponding row of TRAINING % belongs to. 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) allows you to specify the kernel % function KFUN 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 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:

% @(u,v) kfun(u,v,p1,p2).

%

% SVMTRAIN(...,'POLYORDER',ORDER) allows you to specify the order of a

% polynomial kernel. The default order is 3.

%

% SVMTRAIN(...,'MLP_PARAMS',[P1 P2]) allows 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) and P1

% > 0 and P2 < 0. Default values are P1 = 1 and P2 = -1.

%

% SVMTRAIN(...,'METHOD',METHOD) allows you to specify the method used

% to find the separating hyperplane. Options are

%

% 'QP' Use quadratic programming (requires the Optimization Toolbox)

% 'LS' Use least-squares method

%

% If you have the Optimization Toolbox, then the QP method is the default

% method. If not, the only available method is LS.

%

% SVMTRAIN(...,'QUADPROG_OPTS',OPTIONS) allows you to pass an OPTIONS % structure created using OPTIMSET to the QUADPROG function when using

% the 'QP' method. See help optimset 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.

%

% Example:

% % Load the data and select features for classification

% load fisheriris

% data = [meas(:,1), meas(:,2)];

% % Extract the Setosa class

% groups = ismember(species,'setosa');

% % Randomly select training and test sets

% [train, test] = crossvalind('holdOut',groups);

% cp = classperf(groups);

% % Use a linear support vector machine classifier

% svmStruct = svmtrain(data(train,:),groups(train),'showplot',true);

% classes = svmclassify(svmStruct,data(test,:),'showplot',true);

% % See how well the classifier performed

% classperf(cp,classes,test);

% cp.CorrectRate

%

% See also CLASSIFY, KNNCLASSIFY, QUADPROG, SVMCLASSIFY.

相关文档
最新文档