支持向量机(SVM)多分类matlab程序代码 下载本文

内容发布更新时间 : 2024/12/27 6:31:58星期一 下面是文章的全部内容请认真阅读。

%模型训练及数据整理

model_12=svmtrain(class_12_label,class_12_value); model_13=svmtrain(class_13_label,class_13_value); model_14=svmtrain(class_14_label,class_14_value); model_23=svmtrain(class_23_label,class_23_value); model_24=svmtrain(class_24_label,class_24_value); model_34=svmtrain(class_34_label,class_34_value); %??DD?¤2a

[predict_labe1,accuracy_1,dec_values_1] =svmpredict(test_scale_label, test_scale_value, model_12); [predict_labe2,accuracy_2,dec_values_2] =svmpredict(test_scale_label, test_scale_value, model_13); [predict_labe3,accuracy_3,dec_values_3] =svmpredict(test_scale_label, test_scale_value, model_14); [predict_labe4,accuracy_4,dec_values_4] =svmpredict(test_scale_label, test_scale_value, model_23); [predict_labe5,accuracy_5,dec_values_5] =svmpredict(test_scale_label, test_scale_value, model_24); [predict_labe6,accuracy_6,dec_values_6] =svmpredict(test_scale_label, test_scale_value, model_34); predict_labe7=[predict_labe1,predict_labe2,predict_labe3,predict_labe4,predict_labe5,predict_labe6];

[m,n]=size(predict_labe7); predict_labe=zeros(m,1); for i=1:m

n1=0;n2=0;n3=0;n4=0; for j=1:n

if predict_labe7(i,j)==1 n1=n1+1; else

if predict_labe7(i,j)==2 n2=n2+1; else

if predict_labe7(i,j)==3 n3=n3+1; else

if predict_labe7(i,j)==4 n4=n4+1; end end end end end

B=[n1 n2 n3 n4]; max=B(1,1) ;

predict_labe(i,1)=1; for k=1:3

if max<=B(1,k+1) max=B(1,k+1);

predict_labe(i,1)=k+1; end end

end %í3??×?è·?ê count=0; for p=1:m

if test_scale_label(p,1)==predict_labe(p,1) count=count+1; end end

q=count/m;

disp([num2str(q*100),'%'])