-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwhitewine.m
81 lines (65 loc) · 2.39 KB
/
whitewine.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
%% clean the enviroment
close all;
clear;
clc;
format compact;
%% Read the data and load the data
[f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,class] = textread('train-white.csv' , '%f%f%f%f%f%f%f%f%f%f%f%f','delimiter',',');
[t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,c] = textread('test-white.csv' , '%f%f%f%f%f%f%f%f%f%f%f%f','delimiter',',');
[inputn,inputps]=mapminmax( [f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11]') ;
testInput = mapminmax ( [t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11]' ) ;
%% Generate the output matrices
s = length( class ) ;%the number of the colunms should be the same as class number
s_test = length(c);% A test output, help to generate the error matrix
%sprintf( '%d',s)
output = zeros( s , 7 ) ;%initialize the output matrix
output_test = zeros(s_test,7);%initialize the test output matrix
%% initialization: use position to prsent the lable
for i = 1 : s
temp1 = class(i);
collum = temp1 - 2 ;
output( i , collum ) = 1 ;
end
for i = 1 : s_test
temp2 = c(i);
collum_test = temp2 - 2 ;
output_test( i , collum_test ) = 1 ;
end
%% set to generate the network
%net = newff( minmax(input) , [10 10 6] , {'tansig' 'logsig' 'purelin'} , 'traingdx' ) ;
net = newff( inputn ,output', [10] , {'logsig'} , 'traingd' ) ;
%% network setting
net.trainparam.show = 50 ;%the show gap
net.trainparam.epochs = 10000;% epochs used
net.trainparam.goal = 0.0001 ;%the error goals
net.trainParam.lr = 0.001 ;%the learning rate
net =train( net, inputn , output' ) ;%start training
%[t1,t2,t3,t4,t5,t6,t7,t8,t9,c] = textread('test.csv' , '%f%f%f%f%f%f%f%f%f%u','headerlines',1,'delimiter',',');
%% start simulation
Y = sim( net , testInput )
%% accuracy caculation%
[s1 , s2] = size( Y ) ;
hitNum = 0 ;
error_matrix = zeros(7,7);
outindex = zeros(1,s2);
for i = 1 : s2
[m , Index] = max( Y( : , i ) ) ;
Index = Index + 2
outindex(1,i) = Index
if( Index == c(i) )
hitNum = hitNum + 1 ;
label_index = c(i) - 2 ;
error_matrix(label_index,label_index) = error_matrix(label_index,label_index) + 1;
else
Index = Index - 2;
label_index = c(i) - 2 ;
error_matrix(label_index,Index) = error_matrix(label_index,Index) + 1;
end
end
sprintf('The accuracy is %3.3f%%',100 * hitNum / s2 )
%The distribution for prediction and expection%
figure(1)%draw a plot
plot(1:s2,outindex,'r.');%first is predict
hold on;
plot(1:s2,c,'b*');
legend('Predict','Expect');