{"id":1899,"date":"2019-04-08T12:00:00","date_gmt":"2019-04-08T10:00:00","guid":{"rendered":"https:\/\/kindsonthegenius.com\/blog\/machine-learning-101-equation-for-a-line-and-regression-line\/"},"modified":"2026-07-05T03:22:38","modified_gmt":"2026-07-05T01:22:38","slug":"machine-learning-101-equation-for-a-line-and-regression-line","status":"publish","type":"post","link":"https:\/\/kindsonthegenius.com\/blog\/machine-learning-101-equation-for-a-line-and-regression-line\/","title":{"rendered":"Machine Learning 101 \u2013 Equation for a Line and Regression Line"},"content":{"rendered":"<p>Let&#8217;s go back to the regression problem we solved in<a href=\"https:\/\/kindsonthegenius.com\/tempsite\/simple-linear-regression-in-machine-learning-a-simple-tutorial\/\"> Lecture 4<\/a>. We are given a dataset.\u00a0 You need to find the relationship between the two variables.<\/p>\n<p>The record is given below:<\/p>\n<table>\n<tbody>\n<tr style=\"background-color: #f7f6f3;\">\n<td><strong>Spending (x)<\/strong><\/td>\n<td><strong>Profit (t)<\/strong><\/td>\n<\/tr>\n<tr>\n<td>40<\/td>\n<td>90<\/td>\n<\/tr>\n<tr>\n<td>50<\/td>\n<td>110<\/td>\n<\/tr>\n<tr>\n<td>60<\/td>\n<td>130<\/td>\n<\/tr>\n<tr>\n<td>70<\/td>\n<td>150<\/td>\n<\/tr>\n<tr>\n<td>80<\/td>\n<td>170<\/td>\n<\/tr>\n<tr>\n<td>120<\/td>\n<td>250<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Note that we&#8217;ve removed the year column. I have also modified the data.<\/p>\n<p>Also, we would call the Spendings column, <strong>x<\/strong> and the Profit column <strong>y<\/strong>.<\/p>\n<p>Here we can represent this table as:<\/p>\n<p><strong>x<\/strong> = {40, 50, 60, 70, 80, 120}<\/p>\n<p><strong>t<\/strong> = {90, 110, 130, 250, 170, 240}<\/p>\n<p>We read this as:<\/p>\n<p>x is a column vector made up of 6 elements. This can be written also as:<\/p>\n<p><strong>x<\/strong> = {x<sub>1<\/sub>, x<sub>2<\/sub>, . . . , x<sub>n<\/sub>}<sup>T<\/sup> where N = 6<\/p>\n<p>Similarly, for y, we have<\/p>\n<p><strong>t<\/strong> = {t<sub>1<\/sub>, t<sub>2<\/sub>, . . . , t<sub>N<\/sub>}<sup>T<\/sup> where N = 6<\/p>\n<p>&nbsp;<\/p>\n<p>Our goal is to used this data set (training data) to make prediction. So if we have a new value of x, let&#8217;s say x<sub>i<\/sub>, what would be the corresponding t<sub>i<\/sub>.<\/p>\n<p>One way to achieve this is to use a method called curve fitting(or polynomial curve fitting).<\/p>\n<p>Before we discuss curve fitting, let&#8217;s review Equation of a Line.<\/p>\n<p>&nbsp;<\/p>\n<h4><strong>Review of Equation for a Line<\/strong><\/h4>\n<p>If you did some mathematics, then you will remember that every line has an equation.<\/p>\n<p>The equation for a line has the general form:<\/p>\n<p><em>y = mx + c or<\/em><\/p>\n<p><em>y\u00a0 = c + mx<\/em><\/p>\n<p>where;<\/p>\n<p>m is the slope of the line and<\/p>\n<p>c is the intercept of the line on the y axis<\/p>\n<p>This is the generic relationship between x and y that can be plotted on a straight line<\/p>\n<p>This is illustrated in the figure below.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-666\" src=\"https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2020\/09\/Equation-of-a-straight-line-300x254.jpg\" alt=\"Equation of a straight line\" width=\"300\" height=\"254\" \/><\/p>\n<p>This means that the relationship between the two variables is given by the equation of the line.<\/p>\n<p>So if we can find the values of m and c, then we just plug it into the equation.<\/p>\n<p>Now let&#8217;s rewrite this equation in a more Machine Learning way<\/p>\n<p>y =\u00a0\u00df<sub>0<\/sub> +\u00a0\u00df<sub>1<\/sub>x<\/p>\n<p>This then means that regression is simply a problem of finding\u00a0\u00df<sub>0<\/sub>\u00a0and \u00df<sub>1<\/sub>\u00a0which we call the regression coefficient<\/p>\n<p>&nbsp;<\/p>\n<h4><strong>Practical: Using Python to find Regression Coefficients<\/strong><\/h4>\n<p>Let&#8217;s do a little practical. We would find the regression coefficients of using Python.<\/p>\n<p>The Jupyter Notebook screenshot is given below:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-668 size-full\" src=\"https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2020\/09\/Linear-Regression-for-Machine-Learning-101-Lecture-5.jpg\" alt=\"Linear Regression for Machine Learning 101 Lecture 5\" width=\"1048\" height=\"860\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>In the next Lecture, we would continue with Polynomial Curve Equation.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Let&#8217;s go back to the regression problem we solved in Lecture 4. We are given a dataset.\u00a0 You need to find the relationship between the &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-1899","post","type-post","status-publish","format-standard","hentry","category-machine-learning"],"_links":{"self":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/1899","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=1899"}],"version-history":[{"count":1,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/1899\/revisions"}],"predecessor-version":[{"id":2067,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/1899\/revisions\/2067"}],"wp:attachment":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/media?parent=1899"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/categories?post=1899"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/tags?post=1899"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}