Step 4:
clear all;
clc;
close all;
net=feedforwardnet(10); %one hidden layer with 10 nodes
net.name = 'Wine Classification';
load wine_dataset; % load the wine data set
net = train(net,wineInputs,wineTargets); % train the network
Lets pick one of the 178 samples of wine and see which winery the network says it came from:
mysample=wineInputs(:,27); %the 27th wine sample (out of 178)
y=net(mysample);
Note:
Here, the network takes the 27th wine sample and will return 3
numbers. Each of the 3 numbers corresponds to one of the 3
wineries. The winery associated with the largest number is the
winning winery (the network has decided that the wine came from that
winery). This means that we have specified that the output layer
should have 3 nodes (one for each winery). That's because of how
the training data (correct answers) were set up by Matlab. The
corerct answer matrix is 3x178. So for each wine sample, there
are 3 associated output node values. If these three numbers were
[1 0 0] then the correct answer was the first winery. If the
numbers were [ 0 1 0] the correct answer was the second winery,
and if they were [0 0 1] then the wine came from the 3rd winery.
Of course, we could have set up a network with a single output
node and then forced the classification to be based on that single
number. If that single number was between 0 and 1, then we could
have assigned the range 0 to 0.33 to the first wine, 0.33 to 0.66 the
second winery, and 0.66 to 1 to the third winery. But.... that
would require an entirely new (and different) training dataset.
Lets plot the results for the 27th sample using a bar graph:
bar(y)
set(gca,'xticklabel',{'Sonoma';'Bordeaux';'Newport'}); % Place labels along the x axis of the graph.
xlabel('Which Winery?');
Save and run the program to see how the network performed with thie sample wine.
There is more information about how to test the network in the next step.