Sunteți pe pagina 1din 3

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 !.2 5.1 2 "ris#$ir%inica 6 2.& 5.1 1.6 "ris#$ersicolor 6.& !.1 4.& 1.5 "ris#$ersicolor 4.! ! 1.1 '.1 " ris#setosa (e wanta a )) which when we input 6.2 2.& 5.1 1.6 outputs "ris#$ersicolor * we want it to learn how to match the number se+uences on the left with the flower names on the ri%ht. To do this we need to code the inputs ,but since the- are numbers the- code as themsel$es +uite easil-. and also code the outputs ,these are names so the- need to be deliberatel- and e/plicitl- coded.. The file irisnumeric.data codes usin% a local ,or linear. codin% * the first 4 rows now look like 6.5 6 6.& 4.! !.2 2.& !.1 ! 5.1 5.1 4.& 1.1 2 1.6 1.5 '.1 ' 1 1 2

(ork out the linear codin% b- lookin% back to the rows abo$e from iris.data. Look at irisdistributed.data and work out the distributed code. (e could use either of these codin%s * but the distributed will probabl- work better. )ow we will train a network usin% this distributed codin%.

0a%e 1

Csci2412 Labwork

1pen matlab and cop- the files irisdistribted.data and all the .m files in the lab folder to -our matlab area on the 2 dri$e or where$er -ou can write to. 1ur first task is to sort out our input * tar%et pairs. (e will put the inputs into p as columns and the matchin% outputs into t as columns. (e must remember that the 3raw data3 comes in rows * with the first 4 $alues in a row bein% the inputs and the last ! bein% the $alues that classif- the output 4accordin% to a distributed codin%5. rawInput = load('irisdistributed.data'); rowInput=rawInput(:,1:4); rowTarget=rawInput(:,5:7); p=rowInput'; t=rowTarget'; 6emember that the dash ,7. has the effect of transposin% rows into columns ,-ou can see the chan%e n the workspace window.. )ow use the tool bo/ to create a new neural network to learn to classif- the data. "mport the inputs and tar%ets create a feed#forward backprop network. 8et the input ran%e from p use lo%si% as the la-er 1 transfer function and ha$e ! neurons in this la-er 4-ou can set this $alue to an- number -ou like * but we will pick ! for now5 set the la-er 2 transfer function to purelin 4as alwa-s5 . 9ecause of the choice of output codin% there is onl- one suitable $alue for the number of la-er 2 neurons ,i.e. !. because the output si:e from the network has to match the si:e of the tar%et $alues. )ow tr- trainin% the network and see if the errors reach an acceptable $alue. 2ow can we tell; </port the network outputs and compare to the actual $alues 4it ma- be easier to do this comparison in e/cel5 * in particular do the network outputs decode $ia our decodin% scheme to the correct output. 4(e need a decodin% scheme * what should we use;5 There are two m#files pro$ided which tell -ou how accurate the trainin% has been. The check1utput</act tells -ou how man- outputs round to %i$e an e/act match to the e/pected tar%et $alues. The check1utput(inner tells -ou how man- outputs decode $ia the winnin% neuron rule to %i$e a correct answer. The usual decodin% rule for distributed output is the winnin% neuron rule.

Can we improve our approach? =o far we are learnin% from all the data. This is not all that useful because we don>t know if the net will generalise well * it mi%ht ha$e learnt the data ?off b- heart@ and not be able to %et new unseen data correct. To %et round this problem it is usual to train the net on part of the data and test it on unknown ,to the network. data. "f it works well on this test data then we can use it on

0a%e 2

Csci2412 Labwork

completel- unknown data with a de%ree of confidence. This is what the file irisdistmore does * it trains the net on 2A! of the data and then tests it on the other 1A!. Bon>t worrabout the details of how it is pickin% out the testAtrain data that>s Cust a bit of Ci%%erpoker-. "t is also creatin% networks directl- rather than usin% the tool. "f -ou want to use the tool to use this sort of approach -ou would do as follows: 6andoml- split -our input * tar%et pairs into two %roups of data. 4This can be most easildone in e/cel if -ou ha$e reasonable spreadsheet skills * remember -ou ha$e to keep the pairs to%etherD5 Call one the train set ,about 2A! of the data. and the other the test set ,the rest.. Ese the tool to create a network which works with the trainin% set then test it on the test set. "f it seems to be %ood enou%h for re+uirements then use on completel- new data with confidence. 6un irisdistmore and see what happens * read the code. Fou could e/periment with different numbers of hidden neurons to see how performance is affected. Exercise The "talian %o$ernment ha$e a problem with wine fraud * where wines of one t-pe are passed off as wines of a different t-pe. The- ha$e been e/perimentin% with identif-in% wine $ia chemical anal-sis to see if the- can detect the ori%in of wine and catch the fraudsters. The data in wine.data can be used to see if a neural net could do this Cob. 6ead the file wine6eco%nition.doc for information and then decide how to code the data in the file wine.data in a suitable wa- to allow a neural network to work on the problem. Construct a data file of the appropriate kind for readin% into matlab.

0a%e !

S-ar putea să vă placă și