%加载数据
data = csvread('D:\python\anaconda\kaggle\wine.csv',1);
x = data(:,1:13);
y = data(:,14);
y = y+1; %标签值必须为正(含有label=0需要进行此步操作)
%划分数据集
[m,n] = size(x);
index = randsample(m,m);
x_train = x(index(1:130),:)'; %M x N
y_train = y(index(1:130),:)'; %1 x N
x_test = x(index(131:178),:)';
y_test = y(index(131:178),:)';
%建立模型
net = newpnn(x_train,ind2vec(y_train),1.0);
%模型预测
ptrain = vec2ind(sim(net,x_train));
train_error = y_train - ptrain;
train_acc = length(find(train_error==0))/130; %训练集准确率
ptest = vec2ind(sim(net,x_test));
test_error = y_test - ptest;
test_acc = length(find(test_error==0))/48; %测试集准确率
disp(['训练集 acc = ',num2str(train_acc),' 测试集 acc = ',num2str(test_acc)])
%%
%speard = 1.0 train_acc = 1 test_acc = 0.75
%spread = 2.0 train_acc = 1 test_acc = 0.75
%spread = 3.0 train_acc = 1 test_acc = 0.77
%spread = 4.0 train_acc = 1 test_acc = 0.67