{"id":1898,"date":"2019-04-07T12:00:00","date_gmt":"2019-04-07T10:00:00","guid":{"rendered":"https:\/\/kindsonthegenius.com\/blog\/machine-learning-101-simple-regression-problem\/"},"modified":"2026-07-05T03:22:36","modified_gmt":"2026-07-05T01:22:36","slug":"machine-learning-101-simple-regression-problem","status":"publish","type":"post","link":"https:\/\/kindsonthegenius.com\/blog\/machine-learning-101-simple-regression-problem\/","title":{"rendered":"Machine Learning 101 \u2013 Simple Regression Problem"},"content":{"rendered":"<p>This is Lecture 4 of the Machine Learning 101. It follows from<a href=\"https:\/\/kindsonthegenius.com\/tempsite\/machine-learning-101-classes-of-machine-learning-problems\/\"> Lecture 3<\/a>.\u00a0 In this lecture, we would solve some regression problems. So brace up!<\/p>\n<p><strong>First, What is Regression?<\/strong><\/p>\n<p>Simply put, regression is a method used to find relationship between two or more variables.<\/p>\n<p>&nbsp;<\/p>\n<p><b>Problem 1: Marketing\u00a0Ads and Profit<\/b><\/p>\n<p>You have been hired by a departmental store as a Machine Learning expert. Your task is to predict how much profit they would make is they spent $20.00 on advertising. What if they spend additional $120.00 on advertising, how much profit would they make. To help you, they provide you with a history of how spendings on ads and corresponding profit.<\/p>\n<p>The record is given below:<\/p>\n<table>\n<tbody>\n<tr style=\"background-color: #f7f6f3;\">\n<td><strong>Year<\/strong><\/td>\n<td><strong>Spending ($)<\/strong><\/td>\n<td><strong>Profit ($)<\/strong><\/td>\n<\/tr>\n<tr>\n<td>2000<\/td>\n<td>40<\/td>\n<td>160<\/td>\n<\/tr>\n<tr>\n<td>2005<\/td>\n<td>50<\/td>\n<td>250<\/td>\n<\/tr>\n<tr>\n<td>2010<\/td>\n<td>60<\/td>\n<td>360<\/td>\n<\/tr>\n<tr>\n<td>2016<\/td>\n<td>70<\/td>\n<td>490<\/td>\n<\/tr>\n<tr>\n<td>2019<\/td>\n<td>20<\/td>\n<td><span style=\"color: #ff0000;\"><strong>?<\/strong><\/span><\/td>\n<\/tr>\n<tr>\n<td>2020<\/td>\n<td>120<\/td>\n<td><strong><span style=\"color: #ff0000;\">?<\/span><\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p><strong>Solution 1: By Inspection<\/strong><\/p>\n<p>We first examine the given data.<\/p>\n<p>For example, in the year 2000, $40.00 yielded a profit of $160.00. This seems like 40 x 40 = 1600 (but not exactly).<\/p>\n<p>What of (40 x 40) \/ 10? That would give us 1600\/10 = 160.<\/p>\n<p>If we apply it to the year 2005, we would have (50 x 50) \/ 10 = 250.<\/p>\n<p>It seems we have it!<\/p>\n<p>Now we need to find the formula that relates spending\u00a0 to profit. Say we need to find y = f(x)<\/p>\n<p>Let&#8217;s use the variable x to be spending<\/p>\n<p>Also, let&#8217;s use the variable y to be profit<\/p>\n<p>Let&#8217;s also write x = {40, 50, 60, 70, 20, 120)<\/p>\n<p>y = {160, 250, 360, 490, y<sub>5<\/sub>, y<sub>6<\/sub>}<\/p>\n<p>From out analysis, we found out that y = f(x) = x<sup>2<\/sup> \/10<\/p>\n<p>Now it would be easy to find y<sub>5<\/sub> and y<sub>6<\/sub><\/p>\n<p>y<sub>5<\/sub> = f(20) = 20<sup>2<\/sup> \/ 10 = 400\/10 = 40<\/p>\n<p>y<sub>6<\/sub> = f(120) = 120<sup>2<\/sup> \/ 10 = 14400\/10 = 1440<\/p>\n<p>Therefore, if the supermarket spends $20.00 in 2019, then they would make a profit of $40.00<\/p>\n<p>Similarly, if they spend $120.00 in 2020, they would make a profit of $1,440.00<\/p>\n<p>Congrats!. You have solved a problem using Machine Learning<\/p>\n<p>&nbsp;<\/p>\n<p><strong>A Few Notes<\/strong><\/p>\n<p>What we just solved is actually a polynomial regression problem. This is because variable x is not linear in function we derived (we have x2).<\/p>\n<p>Other regression types include<em> linear regression<\/em> and <em>logistic regression<\/em>. We would cover these in subsequent classes.<\/p>\n<p>In the next lecture we would solve some linear regression problem. Then we would also do the same using python.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Practicals: How to Plot in Python<\/strong><\/p>\n<p>To conclude this class, I will show you how to plot this data in Python. I&#8217;m sure you have Jupyter Notebook installed.<\/p>\n<p><strong>Just to remind you:<\/strong> Jupyter notebook provide environment where you write Machine Learning programs using Python syntax.<\/p>\n<p>The screenshot of the complete program is shown below. Ensure to do it yourself.<\/p>\n<p>Notice that we rearranged the data and placed (20, 40)\u00a0 in the first position:<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-659 size-full aligncenter\" src=\"https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2020\/09\/Practicals-of-Tutorial-4.jpg\" alt=\"Plotting in Python\" width=\"839\" height=\"713\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is Lecture 4 of the Machine Learning 101. It follows from Lecture 3.\u00a0 In this lecture, we would solve some regression problems. So brace &hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"pagelayer_contact_templates":[],"_pagelayer_content":"","footnotes":""},"categories":[16],"tags":[],"class_list":["post-1898","post","type-post","status-publish","format-standard","hentry","category-machine-learning"],"_links":{"self":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/1898","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/comments?post=1898"}],"version-history":[{"count":1,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/1898\/revisions"}],"predecessor-version":[{"id":2066,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/1898\/revisions\/2066"}],"wp:attachment":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/media?parent=1898"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/categories?post=1898"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/tags?post=1898"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}