資源簡介
該代碼包括了SVM的多核核函數的分類實現和可視化展示。
代碼片段和文件信息
%svm?model
clc
clear?all
close?all
load?new_data
N?=?size(newX1);%樣本總數
N_train?=?ceil(N*0.75);%選取75%的樣本用于訓練
temp?=?randperm(N);%生成隨機向量
data_train?=?newX(temp(1:N_train)[12]);%訓練數據
group_train?=?newX(temp(1:N_train)3);%訓練數據的標簽
data_test?=?newX(temp(N_train+1:end)[12]);%測試數據
group_test?=?newX(temp(N_train+1:end)3);%測試數據的標簽
%------------------------線性核函數--------------------------%
%subplot(221);
svmStruct1?=?svmtrain(data_traingroup_train‘showplot‘true);%線性SVM訓練
Classes1?=?svmclassify(svmStruct1data_test‘showplot‘true);%線性SVM分類結果
%title(‘線性核函數‘);
xlabel(‘特征1‘)ylabel(‘特征2‘)
CorrectRate1=sum(group_test==Classes1)/(N-N_train)
%------------------------高斯核函數--------------------------%
%subplot(222);
figure
svmStruct2?=?svmtrain(data_traingroup_train‘Kernel_Function‘‘rbf‘‘rbf_sigma‘0.5‘showplot‘true);%高斯徑向基核函數訓練
Classes2?=?svmclassify(svmStruct2data_test‘showplot‘true);
%title(‘高斯徑向基核函數核寬=0.5‘);
xlabel(‘特征1‘)ylabel(‘特征2‘)
CorrectRate2=sum(group_test==Classes2)/(N-N_train)
%--------
評論
共有 條評論