We Post only the Best Stuff

IRIS FLOWER data set in Matlab Tutorial

Step 1 : Download and import data in MS Excel.
  1. First go to UCI Machine Learning Repository.
  2. download iris.data file from that page, or download it by clicking iris.data here. (You may use right click and then save link as option to save it, if it gets opened in browser instead of getting downloaded)
  3. Now open MS Excel.
  4. Open the file iris.data in MS Excel by clicking on open and browsing the file.
  5. A text import wizard will open.
  6. Click on Next.
  7. Then tick tab and comma option in next window, and click on next.
  8. In next box click finish.
  9. Now your data will get arranged in cells automatically.
Step 2 : Arrange Data in MS Excel.
  1. First column is for Sepal Length, second is for Sepal Width, third for Petal Length and fourth is for Petal Width.
  2. Last column represent type of flower.
  3. Inset rt these headings if you want it (for understanding purpose or leave these steps if you don't want to do it, but I recommend doing it for understanding).
  4. Adjust column width for better understanding purpose.
  5. Now click on + icon in bar at bottom and open a new sheet in same excel document, rename it to test.
  6. We will use this sheet's data to check our network's efficiency.
  7. Put "1" in place of all cells having iris-setosa in them.
  8. Similarly putt "2" for iris-versicolor and "3" for iris-virginica.
  9. Now cut data from 5 rows (random or continuous) each category of flowers. i.e. 5 from first 50, 5 from mid 50s and 5 from last 50s.
  10. Paste this data in the new sheet created with name test.
  11. Delete the blank rows formed due to cutting and pasting data, in first sheet.
Step 3 : Matlab Part
  1. First of all, be familiar with commands we will be using here in this tutorial. 
  2. Press "Enter" after writing every command to execute.
  3. clc to clear the main command window, input for making input file, you can use any name like ip, inp or any other as the name what you will give will be used to create the file, we have used input in our example.
  4. output for making output file, the brackets [] are used to make matrix in matlab. target and output are one and same in our example, you can use any name.
  5. semicolon ; is used to separate one row from other in a matrix and if applied after a command before pressing enter, it will just apply the action but will not show you any result on screen.
  6. Now, main working part. Ignore above things if you were unable to understand it, it'll be clear when you use it.
  7. start entering the commands written in bolds, don't forget to press enter after every command.
  8. input=[]
  9. output=[]
  10. test=[]
  11. Now, there will be 3 files in right pane, double click on input and copy paste data from first 4 columns of excel sheet.
  12. Similarly, paste data from 5th column in output file, and from test sheet in test file in matlab.
  13. now, we need to convert rows in columns in excel sheets and vice versa in order to get our data in a format such that it follows rule of sx1. 
  14. For this, enter below commands followed by enter, Pay attention, we are going to use semicolon ; here so that data doesn't come on screen, you can try without semicolon to feel the difference.
  15. input=input';
  16. output=output';
  17. test=test';
  18. nntool
  19. Now, Import data as shown in video below, 
  20. Select input and output files. leave test file untouched at this time,
  21. Now close this window, click in new button, change name of  network1 to iris or leave it if you want, but it will change further commands.
  22. In input data and target data, click on drop down menu and select input and output files respectively.
  23. click on create and close this window.
  24. click on iris and open it, then in second tab, select data as in video,
  25. train network 5-6 times and check regression, it should be same as shown in last picture i.e. regression line should be from lower left corner to upper right corner.
  26. then close all windows as in video.
  27. export iris as in video.
  28. enter commands a=sim(iris,test)
  29. here sim means simulate and it is used to call the network named iris which we created and trained.
  30. This was last command, if network is trained correctly then you should see that first 5 results are near to 1, next 5 to 2 and last 5 to 3, which will prove right training and efficiency of our neural network.
  31. That;'s all for the day.
  32. Enjoy folks
Video for complete understanding.



Share with your friends if you like it or find it useful.

Nitin Kundu

Find author on social media from navigation of site or ask queries in comments section below (Facebook comments).
Support : Contact Us | Privacy Policy | Site Map
Copyright © 2013. Tech Jatt - All Rights Reserved
Site Design by Nitin Kundu Licensed to Tech Jatt
Proudly powered by Blogger