{"id":52,"date":"2022-02-04T07:07:47","date_gmt":"2022-02-04T07:07:47","guid":{"rendered":"https:\/\/blogs.oregonstate.edu\/cannons\/?p=52"},"modified":"2022-02-04T07:07:47","modified_gmt":"2022-02-04T07:07:47","slug":"machine-learning-a-beginners-guide-for-beginners","status":"publish","type":"post","link":"https:\/\/blogs.oregonstate.edu\/cannons\/2022\/02\/04\/machine-learning-a-beginners-guide-for-beginners\/","title":{"rendered":"Machine Learning: A Beginner\u2019s Guide for Beginners"},"content":{"rendered":"\n<p>In the first blog of this series I promised I was going to teach some machine learning (ML) concepts. Since then I haven\u2019t written at all about the cool things I have learned. That is because it is taking me a lot longer to learn them than I expected. There is a lot of math involved, specifically Linear Algebra, which feels like the secret way I should have been doing algebra all along. It is a pretty neat field of mathematics, but sadly one I am unfamiliar with. In case you are interested, I am trying to learn it using <em>Introduction to Linear Algebra, 5th ed.<\/em> by Gilbert Strang. The explanations can be a little confusing sometimes, but the problem sets are amazing.&nbsp;<\/p>\n\n\n\n<p>Anyway, I have learned a few core concepts that I\u2019d like to share. This is an explanation from one beginner to another, so veterans close your ears! Or don\u2019t, and tell me what I got wrong! Today I am going to talk about:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Classification<\/li><li>Feature Mapping<\/li><li>Supervised Learning&nbsp;<\/li><li>Error<\/li><li>Loss<\/li><li>Training Data \/ Test Data<\/li><\/ul>\n\n\n\n<p><strong>Classification<\/strong><\/p>\n\n\n\n<p>One of the core areas of Machine Learning is creating solutions to classification problems. A classification problem could be something like \u201cIs this animal a dog or a cat?\u201d where the \u2018classes\u2019 are \u201cdog\u201d and \u201ccat.\u201d The machine learning challenge is to find the line between the two.&nbsp;<\/p>\n\n\n\n<p><strong>Feature Mapping<\/strong><\/p>\n\n\n\n<p>In ML a \u201c<strong>feature<\/strong>\u201d is something which helps define the data we are looking at. I\u2019ll use the features \u201cWags Tail\u201d and \u201cSticks Butt in Your Face\u201d to help define dogs and cats. Feature Mapping is the practice of turning those abstract concepts into numbers we can do math with. Maybe we count the number of wags per second or the number of butts in your face every hour. With these features we could make a graph of our pets that looks like this.\u00a0<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"714\" height=\"398\" src=\"https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/5212\/files\/2022\/02\/Unclassified.png\" alt=\"\" class=\"wp-image-53\" srcset=\"https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/5212\/files\/2022\/02\/Unclassified.png 714w, https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/5212\/files\/2022\/02\/Unclassified-300x167.png 300w\" sizes=\"auto, (max-width: 714px) 100vw, 714px\" \/><\/figure>\n\n\n\n<p><strong>Supervised Learning<\/strong><\/p>\n\n\n\n<p>This basically means \u201cYou labeled the data\u201d. It is hard to classify something if you don\u2019t know what it is! Well, actually there is another area of Machine Learning called Unsupervised Learning where the data isn\u2019t labeled. In that area the algorithm\u2019s goal is to find patterns like \u201cAll these pets are are grouped over here and all those pets are grouped over there, so they are probably different pets.\u201d<\/p>\n\n\n\n<p>But here we are going to label them. This pet is a \u201cDog\u201d and that pet is a \u201cCat\u201d.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"727\" height=\"398\" src=\"https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/5212\/files\/2022\/02\/Classified.png\" alt=\"\" class=\"wp-image-54\" srcset=\"https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/5212\/files\/2022\/02\/Classified.png 727w, https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/5212\/files\/2022\/02\/Classified-300x164.png 300w\" sizes=\"auto, (max-width: 727px) 100vw, 727px\" \/><\/figure>\n\n\n\n<p><strong>Error<\/strong><\/p>\n\n\n\n<p>The general approach for machine learning is to give this data to a program and say \u201cGuess what this point is!\u201d The program guesses and then compares its guess to the actual answer (the label \u201cDog\u201d or \u201cCat\u201d). The total <strong>Error <\/strong>for the program is the average amount it guessed wrong. In our Dog\/Cat example we would expect the error to be 50% if the program makes completely random guesses. That isn\u2019t great, so what the program does is change the way it guesses to reduce the error.&nbsp;<\/p>\n\n\n\n<p>Let&#8217;s say this was the program\u2019s first guess (the red line). It hypothesized that anything above the red line was a Dog and anything below was a Cat. We can see that it missed 4 of the 14 points, so it has an error of 0.29 or 29% (4 divided by 14).<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"727\" height=\"398\" src=\"https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/5212\/files\/2022\/02\/BadFit.png\" alt=\"\" class=\"wp-image-55\" srcset=\"https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/5212\/files\/2022\/02\/BadFit.png 727w, https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/5212\/files\/2022\/02\/BadFit-300x164.png 300w\" sizes=\"auto, (max-width: 727px) 100vw, 727px\" \/><\/figure>\n\n\n\n<p>That actually isn\u2019t too bad, but it could be better. On the second try the program changes its hypothesis (moves the red line). Again, anything above the line it guesses is a dog and anything below it guesses is a cat.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"727\" height=\"398\" src=\"https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/5212\/files\/2022\/02\/GoodFit.png\" alt=\"\" class=\"wp-image-56\" srcset=\"https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/5212\/files\/2022\/02\/GoodFit.png 727w, https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/5212\/files\/2022\/02\/GoodFit-300x164.png 300w\" sizes=\"auto, (max-width: 727px) 100vw, 727px\" \/><\/figure>\n\n\n\n<p>That is a lot better! It only missed one (the dog who rarely wags his tail but loves to stick his butt in your face). That is an error of 1\/14 or 0.07 or 7%.<\/p>\n\n\n\n<p><strong>Loss<\/strong>&nbsp;<\/p>\n\n\n\n<p>This is a little more complicated and I might get the specifics wrong, but the general concept still applies. There are some situations where guessing certain points incorrectly is a lot worse than other points. Like what if our program was designed to help people who are deathly allergic to cat butts? It wouldn\u2019t be so bad if a dog were mislabeled as a cat, but it could kill someone if a cat were mislabeled as a dog. Loss is an abstract measurement of how awful it is if we guess something wrong. If guessing something wrong was only an average amount of awful, like mislabeling the dog, we might give the incorrect guess a \u201closs\u201d score of 1. On the other hand, we might give mislabeling the cat a loss score of 10. After we make all of our guesses we add up all the loss and divide by the number of points to get the average loss. So if we mislabeled 2 dogs our average loss would be&nbsp;<\/p>\n\n\n\n<p>(1+1) \/ 14 or 0.14.&nbsp;<\/p>\n\n\n\n<p>If we mislabeled 1 dog and 1 cat our average loss would be<\/p>\n\n\n\n<p>(1 + 10) \/ 14 or 0.79<\/p>\n\n\n\n<p>What we do with those loss scores is still a mystery to me, but I assume they get worked back into certain machine learning algorithms to help improve them over time.<\/p>\n\n\n\n<p><strong>Training Data vs. Testing Data<\/strong><\/p>\n\n\n\n<p>All the data we have given our Machine Learning program (algorithm) so far is called the \u201cTraining Data\u201d. It used that training data to figure out the best spot to put the red line, the hypothesis. Now that it is done training we can test that hypothesis by throwing some new never before seen data at it.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"727\" height=\"398\" src=\"https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/5212\/files\/2022\/02\/NewData.png\" alt=\"\" class=\"wp-image-57\" srcset=\"https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/5212\/files\/2022\/02\/NewData.png 727w, https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/5212\/files\/2022\/02\/NewData-300x164.png 300w\" sizes=\"auto, (max-width: 727px) 100vw, 727px\" \/><\/figure>\n\n\n\n<p>Given the location of the testing data above the red line our program will guess that this is a Dog. The \u201ctesting data\u201d is the real world application of the program. How well it classifies (guesses the answer for) new data is the <strong>Test Error<\/strong><\/p>\n\n\n\n<p>That is all for this week! I\u2019ve mostly avoided any math and spoken in terms which might get a few \u201cWell, actually\u2026\u201ds from veteran Machine Learning programmers, but this should still be helpful for learning some general concepts! I\u2019ll share more next week!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the first blog of this series I promised I was going to teach some machine learning (ML) concepts. Since then I haven\u2019t written at all about the cool things I have learned. That is because it is taking me a lot longer to learn them than I expected. There is a lot of math&hellip; <a class=\"more-link\" href=\"https:\/\/blogs.oregonstate.edu\/cannons\/2022\/02\/04\/machine-learning-a-beginners-guide-for-beginners\/\">Continue reading <span class=\"screen-reader-text\">Machine Learning: A Beginner\u2019s Guide for Beginners<\/span><\/a><\/p>\n","protected":false},"author":12041,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-52","post","type-post","status-publish","format-standard","hentry","category-uncategorized","entry"],"_links":{"self":[{"href":"https:\/\/blogs.oregonstate.edu\/cannons\/wp-json\/wp\/v2\/posts\/52","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.oregonstate.edu\/cannons\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.oregonstate.edu\/cannons\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/cannons\/wp-json\/wp\/v2\/users\/12041"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/cannons\/wp-json\/wp\/v2\/comments?post=52"}],"version-history":[{"count":1,"href":"https:\/\/blogs.oregonstate.edu\/cannons\/wp-json\/wp\/v2\/posts\/52\/revisions"}],"predecessor-version":[{"id":58,"href":"https:\/\/blogs.oregonstate.edu\/cannons\/wp-json\/wp\/v2\/posts\/52\/revisions\/58"}],"wp:attachment":[{"href":"https:\/\/blogs.oregonstate.edu\/cannons\/wp-json\/wp\/v2\/media?parent=52"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/cannons\/wp-json\/wp\/v2\/categories?post=52"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/cannons\/wp-json\/wp\/v2\/tags?post=52"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}