資源簡介
matlab程序,基于SVM的數據分類預測——意大利葡萄酒種類識別,里面一個.m文件,一個.mat數據集,直接可以使用。

代碼片段和文件信息
%%?Matlab神經網絡43個案例分析
%?基于SVM的數據分類預測——意大利葡萄酒種類識別
%?by?李洋(faruto)
%?http://www.matlabsky.com
%?Email:faruto@163.com
%?http://weibo.com/faruto?
%?http://blog.sina.com.cn/faruto
%?2013.01.01
%%?清空環境變量
close?all;
clear;
clc;
format?compact;
%%?數據提取
%?載入測試數據wine其中包含的數據為classnumber?=?3wine:178*13的矩陣wine_labes:178*1的列向量
load?chapter_WineClass.mat;
%?畫出測試數據的box可視化圖
figure;
boxplot(wine‘orientation‘‘horizontal‘‘labels‘categories);
title(‘wine數據的box可視化圖‘‘FontSize‘12);
xlabel(‘屬性值‘‘FontSize‘12);
grid?on;
%?畫出測試數據的分維可視化圖
figure
subplot(351);
hold?on
for?run?=?1:178
????plot(runwine_labels(run)‘*‘);
end
xlabel(‘樣本‘‘FontSize‘10);
ylabel(‘類別標簽‘‘FontSize‘10);
title(‘class‘‘FontSize‘10);
for?run?=?2:14
????subplot(35run);
????hold?on;
????str?=?[‘attrib?‘num2str(run-1)];
????for?i?=?1:178
????????plot(iwine(irun-1)‘*‘);
????end
????xlabel(‘樣本‘‘FontSize‘10);
????ylabel(‘屬性值‘‘FontSize‘10);
????title(str‘FontSize‘10);
end
%?選定訓練集和測試集
%?將第一類的1-30第二類的60-95第三類的131-153做為訓練集
train_wine?=?[wine(1:30:);wine(60:95:);wine(131:153:)];
%?相應的訓練集的標簽也要分離出來
train_wine_labels?=?[wine_labels(1:30);wine_labels(60:95);wine_labels(131:153)];
%?將第一類的31-59第二類的96-130第三類的154-178做為測試集
test_wine?=?[wine(31:59:);wine(96:130:);wine(154:178:)];
%?相應的測試集的標簽也要分離出來
test_wine_labels?=?[wine_labels(31:59);wine_labels(96:130);wine_labels(154:178)];
%%?數據預處理
%?數據預處理將訓練集和測試集歸一化到[01]區間
[mtrainntrain]?=?size(train_wine);
[mtestntest]?=?size(test_wine);
dataset?=?[train_wine;test_wine];
%?mapminmax為MATLAB自帶的歸一化函數
[dataset_scaleps]?=?mapminmax(dataset‘01);
dataset_scale?=?dataset_scale‘;
train_wine?=?dataset_scale(1:mtrain:);
test_wine?=?dataset_scale(?(mtrain+1):(mtrain+mtest):?);
%%?SVM網絡訓練
tic;
model?=?svmtrain(train_wine_labels?train_wine?‘-c?2?-g?1‘);
toc;
%%?SVM網絡預測
tic;
[predict_label?accuracydec_value1]?=?svmpredict(test_wine_labels?test_wine?model);
toc;
%%?結果分析
%?測試集的實際分類和預測分類圖
%?通過圖可以看出只有一個測試樣本是被錯分的
figure;
hold?on;
plot(test_wine_labels‘o‘);
plot(predict_label‘r*‘);
xlabel(‘測試集樣本‘‘FontSize‘12);
ylabel(‘類別標簽‘‘FontSize‘12);
legend(‘實際測試集分類‘‘預測測試集分類‘);
title(‘測試集的實際分類和預測分類圖‘‘FontSize‘12);
grid?on;
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????2458??2014-08-20?12:53??chapter_WineClass.m
?????文件???????20168??2010-01-30?18:38??chapter_WineClass.mat
- 上一篇:混沌系統畫分岔圖
- 下一篇:噪聲音樂信號的巴特沃斯帶通濾波器以及均值去噪方法
評論
共有 條評論