LabNotes4

Embed Size (px)

Citation preview

  • 8/13/2019 LabNotes4

    1/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!.25.12 "ris#$ir%inica

    62.&5.11.6 "ris#$ersicolor

    6.&!.14.&1.5 "ris#$ersicolor4.!!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 theri%ht.

    To do this we need to code the inputs ,but since the- are numbers the- code asthemsel$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 !.2 5.1 2 '

    6 2.& 5.1 1.6 1

    6.& !.1 4.& 1.5 1

    4.! ! 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 distributedcode. (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

  • 8/13/2019 LabNotes4

    2/3

    Csci2412 Labwork

    pen matlab and cop- the files irisdistribted.data and all the .m files in the lab folder to

    -our matlab area on the dri$e or where$er -ou can write to.

    ur 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 accordin% to a distributed codin%.

    rawInput = load('irisdistributed.data');

    rowInput=rawInput(:,1:4);

    rowTarget=rawInput(:,5:7);

    p=rowInput';

    t=rowTarget';

    emember that the dash ,7 has the effect of transposin% rows into columns ,-ou can seethe 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 inputran%e from p use lo%si% as the la-er 1 transfer function and ha$e ! neurons in this la-er

    -ou can set this $alue to an- number -ou like * but we will pick ! for now set the la-er

    2 transfer function to purelin as alwa-s . 9ecause of the choice of output codin% there isonl- one suitable $alue for the number of la-er 2 neurons ,i.e. ! because the output sie

    from the network has to match the sie of the tar%et $alues.

    )ow tr- trainin% the network and see if the errors reach an acceptable $alue.

    ow can we tell;

  • 8/13/2019 LabNotes4

    3/3

    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 worr-

    about the details of how it is pickin% out the testAtrain data that>s ust a bit of i%%er-poker-. "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:

    andoml- split -our input * tar%et pairs into two %roups of data. This can be most easil-

    done in e/cel if -ou ha$e reasonable spreadsheet skills * remember -ou ha$e to keep the

    pairs to%etherD Call one the train set ,about 2A! of the data and the other the test set ,therest. 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.

    un irisdistmore and see what happens * read the code.

    ou 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 thefraudsters. The data in wine.data can be used to see if a neural net could do this ob.

    ead the file wineeco%nition.doc for information and then decide how to code the datain 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 !