SVM分类花程序:
clear all;
load fisheriris;
data=[meas(:,1),meas(:,2)];
groups=ismember(species,'setosa');
train=data(1:50,:);
test=data(51:150,:);
%向量机分类
svmstruct=fitcsvm(train,groups(1:50,:),...
'KernelFunction', 'gaussian', ...
'PolynomialOrder', [], ...
'KernelScale', 12, ...
'BoxConstraint', 1, ...
'Standardize', true, ...
'ClassNames', [0; 1]);
classfiles=predict(svmstruct,test);
%最终结果测试
results=sum(classfiles==groups(51:150,:));
acc=results/length(classfiles);
acc=acc*100;
disp(['最终分类率:',num2str(acc),'%']);