我尝试使用一对一的方式运行自己的 svm 代码,但我在选择的函数中出现错误(c,sigma)和绘图函数中的错误,我希望能给我你的帮助,这是代码
clear
clc
close all
%load the data
load dataset
load spacies
[~,~,group] = unique(spacies);
data=dataset(1:12,1:19);
xdata=zscore(data);
%group=spacies(1:end,1);
p=0.5;
[train,test]=crossvalind('HoldOut',group,p);
trainingsample=xdata(train,:);
traininglabel=group(train,1);
testingsample=xdata(test,:);
testinglabel=group(test,1);
numclass=max(group);
for i=1:numclass
for j=i+1:numclass
inij=(traininglabel==i)|(traininglabel==j);
trainingsampleij=trainingsample(inij,:);
traininglabelij=traininglabel(inij,:);
%%k-fold using training data
numfold=8;
indices=crossvalind('kfold',traininglabelij,numfold);
sigma=2.^(-10:1:10);
C=2.^(-5:1:5);
[bestsigma,bestC]=BestParametersRBF(trainingsampleij,...
traininglabelij,sigma,C,indices,numfold);
%%performance
svmStruct=svmtrain(trainingsampleij,traininglabelij,...
'showplot',true,'kernel_function','rbf','rbf_sigma',bestsigma,...
'boxconstraint',bestC);
title(sprintf('Kernel Function: %s','rbf',...
func2str(svmStruct.KernelFunction)),...
'interpreter','none');
classes=svmclassify(svmStruct,testingsample,'showplot',true);
end
end
acc=mean(grp2idx(classes)==grp2idx(testinglabel));