四份类例子%算法一多类支持向量机(一对多算法)closeallclearall%训练数据产生(四类)loadx1loadx2loadx3loadx4xapp=[x1;x2;x3;x4];yapp=[1*ones(1,size(x1,1)),2*ones(1,size(x2,1)),3*ones(1,size(x3,1)),4*ones(1,size(x4,1))]';%-----------------------------------------------------%试验数据产生loadxt1;loadxt2;loadxt3;loadxt4;xtest=[xt1;xt2;xt3;xt4];ytest=[1*ones(1,size(xt1,1))2*ones(1,size(xt2,1))3*ones(1,size(xt3,1))4*ones(1,size(xt4,1))]';%一对多算法%参数设置c=1000;lambda=1e-7;kerneloption=2;kernel='gaussian';verbose=1;%---------------------OneAgainstAllalgorithms----------------nbclass=4;%训练[xsup,w,b,nbsv]=svmmulticlassoneagainstall(xapp,yapp,nbclass,c,lambda,kernel,kerneloption,verbose);%计算训练样本自身分类误差[ypred]=svmmultival(xapp,xsup,w,b,nbsv,kernel,kerneloption);fprintf('\nRateofcorrectclassintrainingdata:%2.2f\n',100*sum(ypred'==yapp)/length(yapp));%测试[ypred,maxi]=svmmultival(xtest,xsup,w,b,nbsv,kernel,kerneloption);%识别率fprintf('\nRateofcorrectclassintestdata:%2.2f\n',100*sum(ypred'==ytest)/length(ytest));