-
大小: 41KB文件類型: .rar金幣: 2下載: 0 次發(fā)布日期: 2021-07-14
- 語言: 其他
- 標(biāo)簽: svm數(shù)據(jù)??
資源簡介
支持矢量機(jī)svm的breast cancer data

代碼片段和文件信息
%%?第28章?支持向量機(jī)的分類——基于乳腺組織電阻抗特性的乳腺癌診斷
%?
%? 該案例作者申明: 1:本人長期駐扎在此板塊里,對該案例提問,做到有問必答。 2:此案例有配套的教學(xué)視頻,視頻下載請點(diǎn)擊http://www.matlabsky.com/forum-91-1.html。? 3:此案例為原創(chuàng)案例,轉(zhuǎn)載請注明出處(《MATLAB智能算法30個(gè)案例分析》)。 4:若此案例碰巧與您的研究有關(guān)聯(lián),我們歡迎您提意見,要求等,我們考慮后可以加在案例里。 5:以下內(nèi)容為初稿,與實(shí)際發(fā)行的書籍內(nèi)容略有出入,請以書籍中的內(nèi)容為準(zhǔn)。
%?
%%?清空環(huán)境變量
clear?all
clc
%%?導(dǎo)入數(shù)據(jù)
load?BreastTissue_data.mat
%?隨機(jī)產(chǎn)生訓(xùn)練集和測試集
n?=?randperm(size(matrix1));
%?訓(xùn)練集——80個(gè)樣本
train_matrix?=?matrix(n(1:80):);
train_label?=?label(n(1:80):);
%?測試集——26個(gè)樣本
test_matrix?=?matrix(n(81:end):);
test_label?=?label(n(81:end):);
%%?數(shù)據(jù)歸一化
[Train_matrixPS]?=?mapminmax(train_matrix‘);
Train_matrix?=?Train_matrix‘;
Test_matrix?=?mapminmax(‘a(chǎn)pply‘test_matrix‘PS);
Test_matrix?=?Test_matrix‘;
%%?SVM創(chuàng)建/訓(xùn)練(RBF核函數(shù))
%?尋找最佳c/g參數(shù)——交叉驗(yàn)證方法
[cg]?=?meshgrid(-10:0.2:10-10:0.2:10);
[mn]?=?size(c);
cg?=?zeros(mn);
eps?=?10^(-4);
v?=?5;
bestc?=?1;
bestg?=?0.1;
bestacc?=?0;
for?i?=?1:m
????for?j?=?1:n
????????cmd?=?[‘-v?‘num2str(v)‘?-t?2‘‘?-c?‘num2str(2^c(ij))‘?-g?‘num2str(2^g(ij))];
????????cg(ij)?=?svmtrain(train_labelTrain_matrixcmd);?????
????????if?cg(ij)?>?bestacc
????????????bestacc?=?cg(ij);
????????????bestc?=?2^c(ij);
????????????bestg?=?2^g(ij);
????????end????????
????????if?abs(?cg(ij)-bestacc?)<=eps?&&?bestc?>?2^c(ij)?
????????????bestacc?=?cg(ij);
????????????bestc?=?2^c(ij);
????????????bestg?=?2^g(ij);
????????end???????????????
????end
end
cmd?=?[‘?-t?2‘‘?-c?‘num2str(bestc)‘?-g?‘num2str(bestg)];
%?創(chuàng)建/訓(xùn)練SVM模型
model?=?svmtrain(train_labelTrain_matrixcmd);
%%?SVM仿真測試
[predict_label_1accuracy_1]?=?svmpredict(train_labelTrain_matrixmodel);
[predict_label_2accuracy_2]?=?svmpredict(test_labelTest_matrixmodel);
result_1?=?[train_label?predict_label_1];
result_2?=?[test_label?predict_label_2];
%%?繪圖
figure
plot(1:length(test_label)test_label‘r-*‘)
hold?on
plot(1:length(test_label)predict_label_2‘b:o‘)
grid?on
legend(‘真實(shí)類別‘‘預(yù)測類別‘)
xlabel(‘測試集樣本編號(hào)‘)
ylabel(‘測試集樣本類別‘)
string?=?{‘測試集SVM預(yù)測結(jié)果對比(RBF核函數(shù))‘;
??????????[‘a(chǎn)ccuracy?=?‘?num2str(accuracy_2(1))?‘%‘]};
title(string)
%%
%?
%? 相關(guān)論壇: