www.pudn.com > wine.rar > wine.asv, change:2011-05-28,size:1217b


clear; 
clc; 
 
%将.txt转成.xls,再file->import data,最后命令save 
load wine.mat 
wine_labels = wine(:,1); 
 
% 画出测试数据的可视化图 
figure 
subplot(3,5,1); 
hold on 
for run = 1:178 
    plot(run,wine_labels(run)); 
end 
title('class','FontSize',10); 
 
for run = 2:14 
    subplot(3,5,run); 
    hold on; 
    str = ['attrib ',num2str(run-1)]; 
    for i = 1:178 
        plot(i,wine(i,run-1)); 
    end 
    title(str,'FontSize',10); 
end 
 
%载入数据,分为训练集和测试集 
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)]; 
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)]; 
 
%数据归一化 
[mtrain,ntrain] = size(train_wine); 
[mtest,ntest] = size(test_wine); 
dataset = [train_wine,test_wine]; 
[dataset_scale,ps] = mapminmax(dataset',0,1); 
dataset_scale = dataset_scale'; 
train_wine = dataset_scale(1:mtrain,:); 
test_wine = dataset_scale((mtrain+1):(mtrain+mtest),:); 
 
%SVM训练与预测 
model = svmtrain(train_wine_labels,train_wine,'-c 2 -g 1'); 
[predict_label, accuracy] = svmpredict(test_wine_labels,test_wine,model);