LabNotes4

advertisement
Csci2412 Labwork
Laboratory Sessions – neural network exercises.
Lab 4
Learning outcomes
You will have experience of creating feed forward neural networks for yourself.
You will know the importance of using test data which is independent of the
training data.
Creating networks
First of all inspect the data that is in the file iris.data.
This is the information that we will use to train our network.
Look at the first 4 rows:
6.5,3.2,5.1,2, Iris-virginica
6,2.7,5.1,1.6, Iris-versicolor
6.7,3.1,4.7,1.5, Iris-versicolor
4.3,3,1.1,0.1,I ris-setosa
We wanta a NN which when we input 6.2, 2.7, 5.1, 1.6 outputs Iris-versicolor – we want
it to learn how to match the number sequences on the left with the flower names on the
right.
To do this we need to code the inputs (but since they are numbers they code as
themselves quite easily) and also code the outputs (these are names so they need to be
deliberately and explicitly coded).
The file irisnumeric.data codes using a local (or linear) coding – the first 4 rows now
look like
6.5
6
6.7
4.3
3.2
2.7
3.1
3
5.1
5.1
4.7
1.1
2
1.6
1.5
0.1
0
1
1
2
Work out the linear coding by looking back to the rows above from iris.data.
Look at irisdistributed.data and work out the distributed code. We could use either of
these codings – but the distributed will probably work better.
Now we will train a network using this distributed coding.
Page 1
Csci2412 Labwork
Open matlab and copy the files irisdistribted.data and all the .m files in the lab folder to
your matlab area on the H drive or wherever you can write to.
Our first task is to sort out our input – target pairs. We will put the inputs into p as
columns and the matching outputs into t as columns. We must remember that the 'raw
data' comes in rows – with the first 4 values in a row being the inputs and the last 3 being
the values that classify the output [according to a distributed coding].
rawInput = load('irisdistributed.data');
rowInput=rawInput(:,1:4);
rowTarget=rawInput(:,5:7);
p=rowInput';
t=rowTarget';
Remember that the dash (‘) has the effect of transposing rows into columns (you can see
the change n the workspace window).
Now use the tool box to create a new neural network to learn to classify the data.
Import the inputs and targets, create a feed-forward backprop network. Get the input
range from p, use logsig as the layer 1 transfer function and have 3 neurons in this layer
[you can set this value to any number you like – but we will pick 3 for now], set the layer
2 transfer function to purelin [as always] . Because of the choice of output coding there is
only one suitable value for the number of layer 2 neurons (i.e. 3) because the output size
from the network has to match the size of the target values.
Now try training the network and see if the errors reach an acceptable value.
How can we tell? Export the network outputs and compare to the actual values [it may be
easier to do this comparison in excel] – in particular do the network outputs decode via
our decoding scheme to the correct output. [We need a decoding scheme – what should
we use?]
There are two m-files provided which tell you how accurate the training has been. The
checkOutputExact tells you how many outputs round to give an exact match to the
expected target values. The checkOutputWinner tells you how many outputs decode via
the winning neuron rule to give a correct answer. The usual decoding rule for distributed
output is the winning neuron rule.
Can we improve our approach?
So far we are learning from all the data.
This is not all that useful because we don’t know if the net will generalise well – it might
have learnt the data “off by heart” and not be able to get new, unseen data correct.
To get round this problem it is usual to train the net on part of the data and test it on
unknown (to the network) data. If it works well on this test data then we can use it on
Page 2
Csci2412 Labwork
completely unknown data with a degree of confidence. This is what the file irisdistmore
does – it trains the net on 2/3 of the data and then tests it on the other 1/3. Don’t worry
about the details of how it is picking out the test/train data that’s just a bit of jiggery
pokery. It is also creating networks directly rather than using the tool. If you want to use
the tool to use this sort of approach you would do as follows:
Randomly split your input – target pairs into two groups of data. [This can be most easily
done in excel if you have reasonable spreadsheet skills – remember you have to keep the
pairs together!] Call one the train set (about 2/3 of the data) and the other the test set (the
rest). Use the tool to create a network which works with the training set then test it on the
test set. If it seems to be good enough for requirements then use on completely new data
with confidence.
Run irisdistmore and see what happens – read the code.
You could experiment with different numbers of hidden neurons to see how performance
is affected.
Exercise
The Italian government have a problem with wine fraud – where wines of one type are
passed off as wines of a different type. They have been experimenting with identifying
wine via chemical analysis to see if they can detect the origin of wine and catch the
fraudsters. The data in wine.data can be used to see if a neural net could do this job.
Read the file wineRecognition.doc for information and then decide how to code the data
in the file wine.data in a suitable way to allow a neural network to work on the problem.
Construct a data file of the appropriate kind for reading into matlab.
Page 3
Download