{"id":1912,"date":"2019-04-25T12:00:00","date_gmt":"2019-04-25T10:00:00","guid":{"rendered":"https:\/\/kindsonthegenius.com\/blog\/lecture-17-multiple-linear-regression\/"},"modified":"2026-07-05T03:23:07","modified_gmt":"2026-07-05T01:23:07","slug":"lecture-17-multiple-linear-regression","status":"publish","type":"post","link":"https:\/\/kindsonthegenius.com\/blog\/lecture-17-multiple-linear-regression\/","title":{"rendered":"Machine Learning 101 \u2013 Multiple Linear Regression"},"content":{"rendered":"<p>You already know of <a href=\"https:\/\/kindsonthegenius.com\/tempsite\/machine-learning-101-simple-regression-problem\/\">Simple Linear Regression<\/a>. You also know of <a href=\"https:\/\/kindsonthegenius.com\/tempsite\/machine-learning-101-basics-of-logistic-regression\/\">Logistic Regression<\/a>. Now we would discuss Multiple Linear Regression.<\/p>\n<p>This is a case where we have more than one predictor(independent) variables.<\/p>\n<p>Let&#8217;s illustrate using the advertising dataset. You can get this dataset from this <a href=\"https:\/\/drive.google.com\/file\/d\/1S5z32dr4a20D74M3M3IpujHcfcWZvpy3\/view?usp=sharing\" target=\"_blank\" rel=\"noopener\">link.<\/a>\u00a0I&#8217;ts a csv file.\u00a0 Just download it, so you can use it for this lesson.<\/p>\n<p>A cross-section of the dataset is shown below<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-794 \" src=\"https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2020\/09\/Advertising-Data.jpg\" alt=\"Advertising Data\" width=\"594\" height=\"392\" \/><\/p>\n<p>Meanwhile to view the dataset: first download the advertising dataset to your computer(I saved mine in D:\/data\/Advertising.csv).<\/p>\n<p>Then use the code below to load it into Jupyter Notebook.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-795 \" src=\"https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2020\/09\/Advertising-data-in-Python.jpg\" alt=\"\" width=\"1028\" height=\"458\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>In this dataset, we can see that there are three predictor variables: TV, radio and newspaper. Then we have one response variable: sales. We are interested in knowing how\u00a0 the three predictor variables affect the response variable.<\/p>\n<p>One way to do this is by running three separate linear regression lines, one for each of the 3 predictor variables.<\/p>\n<p>So we can find how TV affects sales. In the case of TV we have<\/p>\n<p style=\"text-align: center;\"><strong>sales = 703.3 + 4.7TV<\/strong><\/p>\n<p>From the equation, we see that $1,000 increase in spending on TV ads would result in $4.57 units increase in sales.<\/p>\n<p>Similarly, for radio and newspaper, we have:<\/p>\n<p style=\"text-align: center;\"><strong>sales = 931.2 + 202.5radio\u00a0<\/strong><\/p>\n<p style=\"text-align: center;\"><strong>sales = 1235.1 + 5.47newspaper<\/strong><\/p>\n<p>You can watch the video lesson to see how these is obtained.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>The problem with Linear Regression<\/strong><\/p>\n<p>The challenge with this approach is that each of these equations ignores the effect of the other variables. Also, we don&#8217;t know how each of the variables affect the other. So in real scenario, we want to see how the three variables together affect sales. We can achieve this using multiple linear regression.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>How Multiple Linear Regression Works<\/strong><\/p>\n<p>Multiple linear regression is an extension of linear regression. It simply has to now be adjusted to include multiple\u00a0 predictor variables. Hence, in multiple linear regression, each predictor variable has its own coefficient all in a single model.<\/p>\n<p>Assuming we have p predictor variables, then the multiple regression model will take the form:<\/p>\n<p style=\"text-align: center;\"><strong>Y =\u00a0\u03b2<sub>0<\/sub> +\u00a0\u03b2<sub>1<\/sub>X<sub>1<\/sub> +\u00a0\u00a0\u03b2<sub>2<\/sub>X<sub>2<\/sub> + . . . +\u00a0\u03b2<sub>p<\/sub>X<sub>p<\/sub>\u00a0 +\u00a0\ud835\udf16<\/strong><\/p>\n<p>Here,\u00a0 X<sub>j<\/sub> represents the jth predictor variable and\u00a0\u03b2<sub>j<\/sub> indicates the relationship between that variable and the response.<\/p>\n<p>Also, \u03b2<sub>j<\/sub> is interpreted as the average effect a unit increase in X<sub>j<\/sub> will have on Y, while holding all other predictor variables fixed.<\/p>\n<p>Now we can rewrite this model using TV, radio and newspaper as the predictor variables. So we have:<\/p>\n<p style=\"text-align: center;\"><strong>sales = \u03b2<sub>0<\/sub> + \u03b2<sub>1<\/sub> \u00d7 TV + \u03b2<sub>2<\/sub> \u00d7 radio + \u03b2<sub>3<\/sub> \u00d7 newspaper +\u00a0\ud835\udf16<\/strong><\/p>\n<p>Now the question is:<\/p>\n<p>How do we determine the regression coefficients for multiple regression? We would examine this in the next Lecture.<\/p>\n<p>&nbsp;<\/p>\n<h4><strong>Python Practicals<\/strong><\/h4>\n<p>In this practical, we would import the advertising data to Jupyter notebook.<\/p>\n<p>Next, we would do a subplot of:<\/p>\n<ul>\n<li>TV vs sales<\/li>\n<li>radio vs sales<\/li>\n<li>newspaper vs sales<\/li>\n<\/ul>\n<p>Then we would perform separate linear regression for each of them.<\/p>\n<p>Finally we fit a regression line through each of the plots and determine the effect each of the predictor variables have on the value of sales.<\/p>\n<p>You can find the screenshot of this practical below.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>1. Import dataset<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-796 size-full\" src=\"https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2020\/09\/Multiple-Linear-Regression-1.jpg\" alt=\"\" width=\"958\" height=\"230\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>2. Do a scatter plot<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-797 size-full\" src=\"https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2020\/09\/Multiple-Linear-Regression-2.jpg\" alt=\"\" width=\"851\" height=\"411\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>3. Perform separate linear regression<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-798 size-full\" src=\"https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2020\/09\/Multiple-Linear-Regression-3.jpg\" alt=\"\" width=\"884\" height=\"388\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>You already know of Simple Linear Regression. You also know of Logistic Regression. Now we would discuss Multiple Linear Regression. This is a case where &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-1912","post","type-post","status-publish","format-standard","hentry","category-machine-learning"],"_links":{"self":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/1912","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=1912"}],"version-history":[{"count":1,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/1912\/revisions"}],"predecessor-version":[{"id":2080,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/1912\/revisions\/2080"}],"wp:attachment":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/media?parent=1912"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/categories?post=1912"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/tags?post=1912"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}