{"id":501,"date":"2020-04-13T20:21:52","date_gmt":"2020-04-13T14:51:52","guid":{"rendered":"https:\/\/dphi.tech\/?p=501"},"modified":"2022-11-15T15:39:05","modified_gmt":"2022-11-15T10:09:05","slug":"tutorial-on-linear-regression-using-gradient-descent","status":"publish","type":"post","link":"https:\/\/aiplanet.com\/blog\/tutorial-on-linear-regression-using-gradient-descent\/","title":{"rendered":"Tutorial on Linear Regression using Gradient Descent"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">In this article I will talk about how the gradient descent algorithm works and implement it from scratch in python. <\/h4>\n\n\n\n<h4 class=\"wp-block-heading\">First, we will look at what linear regression is, and then we will define the loss function. We learn how the gradient descent algorithm works and finally we will implement it on a given data set and make predictions.<\/h4>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img decoding=\"async\" src=\"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2020\/04\/LR3_1.gif\" alt=\"\" class=\"wp-image-502\"\/><figcaption>The values of m and c are updated at each iteration to get the optimal solution<\/figcaption><\/figure><\/div>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"063f\">Linear Regression<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">In statistics, linear regression is a linear approach to modelling the relationship between a dependent variable and one or more independent variables. Let&nbsp;<strong>X<\/strong>&nbsp;be the independent variable and&nbsp;<strong>Y<\/strong>&nbsp;be the dependent variable. We will define a linear relationship between these two variables as follows:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img decoding=\"async\" src=\"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2020\/04\/LR3_2.png\" alt=\"\" class=\"wp-image-503\"\/><\/figure><\/div>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img decoding=\"async\" src=\"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2020\/04\/LR3_3.gif\" alt=\"\" class=\"wp-image-504\"\/><figcaption>Source:&nbsp;<a rel=\"noreferrer noopener\" href=\"http:\/\/www.nabla.hr\/SlopeInterceptLineEqu.gif\" target=\"_blank\">http:\/\/www.nabla.hr\/SlopeInterceptLineEqu.gif<\/a><\/figcaption><\/figure><\/div>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"789a\">Loss Function<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">The loss is the error in our predicted value of&nbsp;<strong>m<\/strong>&nbsp;and&nbsp;<strong>c<\/strong>. Our goal is to minimize this error to obtain the most accurate value of&nbsp;<strong>m<\/strong>&nbsp;and&nbsp;<strong>c<\/strong>.<br>We will use the Mean Squared Error function to calculate the loss. There are three steps in this function:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Find the difference between the actual y and predicted y value(y = mx + c), for a given x.<\/li><li>Square this difference.<\/li><li>Find the mean of the squares for every value in X.<\/li><\/ol>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img decoding=\"async\" src=\"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2020\/04\/LR3_4.jpg\" alt=\"\" class=\"wp-image-505\"\/><figcaption>Mean Squared Error Equation<\/figcaption><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Here y\u1d62 is the actual value and \u0233\u1d62 is the predicted value. Lets substitute the value of \u0233\u1d62:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img decoding=\"async\" src=\"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2020\/04\/LR3_5.jpg\" alt=\"\" class=\"wp-image-506\"\/><figcaption>Substituting the value of \u0233\u1d62<\/figcaption><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">So we square the error and find the mean. Hence, the name is Mean Squared Error. Now that we have defined the loss function, let&#8217;s get into the interesting part \u2014 minimizing it and finding&nbsp;<strong>m<\/strong>&nbsp;and&nbsp;<strong>c.<\/strong><\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"ee05\">The Gradient Descent Algorithm<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">Gradient descent is an iterative optimization algorithm to find the minimum of a function. Here that function is our Loss Function.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Understanding Gradient Descent<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2020\/04\/LR3_6-1024x681.jpg\" alt=\"\" class=\"wp-image-507\"\/><figcaption>Illustration of how the gradient descent algorithm works<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Imagine a valley and a person with no sense of direction who wants to get to the bottom of the valley. He goes down the slope and takes large steps when the slope is steep and small steps when the slope is less steep. He decides his next position based on his current position and stops when he gets to the bottom of the valley which was his goal.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><br>Let\u2019s try applying gradient descent to&nbsp;<strong>m<\/strong>&nbsp;and&nbsp;<strong>c<\/strong>&nbsp;and approach it step by step:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Initially let m = 0 and c = 0. Let L be our learning rate. This controls how much the value of&nbsp;<strong>m<\/strong>&nbsp;changes with each step. L could be a small value like 0.0001 for good accuracy.<\/li><li>Calculate the partial derivative of the loss function with respect to m, and plug in the current values of x, y, m and c in it to obtain the derivative value&nbsp;<strong>D<\/strong>.<\/li><\/ol>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img decoding=\"async\" src=\"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2020\/04\/LR3_7.jpg\" alt=\"\" class=\"wp-image-508\"\/><figcaption>Derivative with respect to&nbsp;<strong>m<\/strong><\/figcaption><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">D\u2098 is the value of the partial derivative with respect to&nbsp;<strong>m<\/strong>. Similarly lets find the partial derivative with respect to&nbsp;<strong>c<\/strong>, Dc :<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img decoding=\"async\" src=\"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2020\/04\/LR3_8.jpg\" alt=\"\" class=\"wp-image-509\"\/><figcaption>Derivative with respect to&nbsp;<strong>c<\/strong><\/figcaption><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">3. Now we update the current value of&nbsp;<strong>m<\/strong>&nbsp;and&nbsp;<strong>c<\/strong>&nbsp;using the following equation:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img decoding=\"async\" src=\"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2020\/04\/LR3_9.jpg\" alt=\"\" class=\"wp-image-510\"\/><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">4. We repeat this process until our loss function is a very small value or ideally 0 (which means 0 error or 100% accuracy). The value of&nbsp;<strong>m<\/strong>&nbsp;and&nbsp;<strong>c<\/strong>&nbsp;that we are left with now will be the optimum values.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now going back to our analogy,&nbsp;<strong>m<\/strong>&nbsp;can be considered the current position of the person.&nbsp;<strong>D<\/strong>&nbsp;is equivalent to the steepness of the slope and&nbsp;<strong>L<\/strong>&nbsp;can be the speed with which he moves. Now the new value of&nbsp;<strong>m<\/strong>&nbsp;that we calculate using the above equation will be his next position, and&nbsp;<strong>L\u00d7D<\/strong>&nbsp;will be the size of the steps he will take. When the slope is more steep (<strong>D<\/strong>&nbsp;is more) he takes longer steps and when it is less steep (<strong>D<\/strong>&nbsp;is less), he takes smaller steps. Finally he arrives at the bottom of the valley which corresponds to our loss = 0.<br>Now with the optimum value of&nbsp;<strong>m<\/strong>&nbsp;and&nbsp;<strong>c<\/strong>&nbsp;our model is ready to make predictions!<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"ad89\">Implementing the Model<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">Now let\u2019s convert everything above into code and see our model in action!<\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/adarsh1021\/b33108e9a6c899583afabf169b6bae6d.js\"><\/script>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img decoding=\"async\" src=\"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2020\/04\/LR3_10.png\" alt=\"\" class=\"wp-image-511\"\/><\/figure><\/div>\n\n\n\n<script src=\"https:\/\/gist.github.com\/adarsh1021\/bc11656edb9eb82224d450b72c4859ec.js\"><\/script>\n\n\n\n<p class=\"has-cyan-bluish-gray-background-color has-background wp-block-paragraph\">1.4796491688889395 0.10148121494753726<\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/adarsh1021\/926d654d98583fe032db89600a89a1cc.js\"><\/script>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img decoding=\"async\" src=\"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2020\/04\/LR3_11.png\" alt=\"\" class=\"wp-image-512\"\/><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Gradient descent is one of the simplest and widely used algorithms in machine learning, mainly because it can be applied to any function to optimize it. Learning it lays the foundation to mastering machine learning.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The article can be found in this video tutorial &#8211; <\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe title=\"Linear Regression using Gradient Descent in Python - Machine Learning Basics\" width=\"500\" height=\"281\" src=\"https:\/\/www.youtube.com\/embed\/4PHI11lX11I?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Find the data set and code here:&nbsp;<\/em><a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/chasinginfinity\/ml-from-scratch\/tree\/master\/02%20Linear%20Regression%20using%20Gradient%20Descent\" target=\"_blank\">https:\/\/github.com\/chasinginfinity\/ml-from-scratch\/tree\/master\/02%20Linear%20Regression%20using%20Gradient%20Descent<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em><strong>Note:\u00a0<\/strong>T<em>his article was originally published on\u00a0<a href=\"https:\/\/towardsdatascience.com\/linear-regression-using-gradient-descent-97a6c8700931\">towardsdatascience.com<\/a>, and kindly contributed to AI Planet (formerly DPhi)<\/em><\/em> <em><em>to spread the knowledge.<\/em><\/em><\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><strong><em>Become a guide. Become a mentor.<\/em><\/strong><br><em>We at AI Planet (formerly DPhi), welcome you to share your experience in data science \u2013 be it your learning journey, experience while participating in Data Science Challenges, data science\u00a0projects, tutorials and anything that is related to Data Science. Your learnings could help a large number of aspiring data scientists!\u00a0Interested? Submit\u00a0<a rel=\"noreferrer noopener\" href=\"https:\/\/docs.google.com\/forms\/d\/e\/1FAIpQLSdOMt4yfkgkWxWIkvQMuuJiwsc21mCV8IxPqGLhj1uZ6oLJ9Q\/viewform\" target=\"_blank\">here<\/a>.\u00a0<\/em><\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>This article talks about how the gradient descent algorithm works and describes the implementation from scratch in python. <\/p>\n","protected":false},"author":11,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[20,29,28,22,24],"class_list":["post-501","post","type-post","status-publish","format-standard","hentry","category-datascience","tag-datascience","tag-gradient-descent","tag-linear-regression","tag-machine-learning","tag-python"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Tutorial on Linear Regression using Gradient Descent - AI Planet<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/aiplanet.com\/blog\/tutorial-on-linear-regression-using-gradient-descent\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Tutorial on Linear Regression using Gradient Descent - AI Planet\" \/>\n<meta property=\"og:description\" content=\"This article talks about how the gradient descent algorithm works and describes the implementation from scratch in python.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/aiplanet.com\/blog\/tutorial-on-linear-regression-using-gradient-descent\/\" \/>\n<meta property=\"og:site_name\" content=\"AI Planet\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/aiplanet\/\" \/>\n<meta property=\"article:published_time\" content=\"2020-04-13T14:51:52+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-11-15T10:09:05+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2020\/04\/LR3_1.gif\" \/>\n<meta name=\"author\" content=\"Adarsh Menon\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Adarsh Menon\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/aiplanet.com\\\/blog\\\/tutorial-on-linear-regression-using-gradient-descent\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/aiplanet.com\\\/blog\\\/tutorial-on-linear-regression-using-gradient-descent\\\/\"},\"author\":{\"name\":\"Adarsh Menon\",\"@id\":\"https:\\\/\\\/aiplanet.com\\\/blog\\\/#\\\/schema\\\/person\\\/b121996cdbe68ef54fbc4683ff368a27\"},\"headline\":\"Tutorial on Linear Regression using Gradient Descent\",\"datePublished\":\"2020-04-13T14:51:52+00:00\",\"dateModified\":\"2022-11-15T10:09:05+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/aiplanet.com\\\/blog\\\/tutorial-on-linear-regression-using-gradient-descent\\\/\"},\"wordCount\":896,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/aiplanet.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/aiplanet.com\\\/blog\\\/tutorial-on-linear-regression-using-gradient-descent\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/aiplanet.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/04\\\/LR3_1.gif\",\"keywords\":[\"datascience\",\"gradient descent\",\"linear regression\",\"machine learning\",\"python\"],\"articleSection\":[\"datascience\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/aiplanet.com\\\/blog\\\/tutorial-on-linear-regression-using-gradient-descent\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/aiplanet.com\\\/blog\\\/tutorial-on-linear-regression-using-gradient-descent\\\/\",\"url\":\"https:\\\/\\\/aiplanet.com\\\/blog\\\/tutorial-on-linear-regression-using-gradient-descent\\\/\",\"name\":\"Tutorial on Linear Regression using Gradient Descent - AI Planet\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/aiplanet.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/aiplanet.com\\\/blog\\\/tutorial-on-linear-regression-using-gradient-descent\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/aiplanet.com\\\/blog\\\/tutorial-on-linear-regression-using-gradient-descent\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/aiplanet.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/04\\\/LR3_1.gif\",\"datePublished\":\"2020-04-13T14:51:52+00:00\",\"dateModified\":\"2022-11-15T10:09:05+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/aiplanet.com\\\/blog\\\/tutorial-on-linear-regression-using-gradient-descent\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/aiplanet.com\\\/blog\\\/tutorial-on-linear-regression-using-gradient-descent\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/aiplanet.com\\\/blog\\\/tutorial-on-linear-regression-using-gradient-descent\\\/#primaryimage\",\"url\":\"https:\\\/\\\/aiplanet.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/04\\\/LR3_1.gif\",\"contentUrl\":\"https:\\\/\\\/aiplanet.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/04\\\/LR3_1.gif\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/aiplanet.com\\\/blog\\\/tutorial-on-linear-regression-using-gradient-descent\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/aiplanet.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Tutorial on Linear Regression using Gradient Descent\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/aiplanet.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/aiplanet.com\\\/blog\\\/\",\"name\":\"AI Planet, Formerly DPhi\",\"description\":\"AI Planet (formerly DPhi) is a global ecosystem that aims to educate and empower individuals and organizations to build and utilize artificial intelligence (AI). With a community of over 300,000 AI specialists and enthusiasts, we offer a range of products and have helped drive innovative solutions for various industries. Our ultimate goal is to make AI education accessible to everyone and use AI to tackle important business and social challenges.\",\"publisher\":{\"@id\":\"https:\\\/\\\/aiplanet.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/aiplanet.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/aiplanet.com\\\/blog\\\/#organization\",\"name\":\"AI Planet, Formerly DPhi\",\"url\":\"https:\\\/\\\/aiplanet.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/aiplanet.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/aiplanet.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/11\\\/Size48-Large-1.png\",\"contentUrl\":\"https:\\\/\\\/aiplanet.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/11\\\/Size48-Large-1.png\",\"width\":48,\"height\":48,\"caption\":\"AI Planet, Formerly DPhi\"},\"image\":{\"@id\":\"https:\\\/\\\/aiplanet.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/aiplanet\\\/\",\"https:\\\/\\\/www.instagram.com\\\/aiplanet_community\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/aiplanet\\\/\",\"https:\\\/\\\/www.youtube.com\\\/@aiplanet\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/aiplanet.com\\\/blog\\\/#\\\/schema\\\/person\\\/b121996cdbe68ef54fbc4683ff368a27\",\"name\":\"Adarsh Menon\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/c60cd7eab96e2afd47ba36714163d1f75f4f470b5a5da376a761e1a0f74b12bf?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/c60cd7eab96e2afd47ba36714163d1f75f4f470b5a5da376a761e1a0f74b12bf?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/c60cd7eab96e2afd47ba36714163d1f75f4f470b5a5da376a761e1a0f74b12bf?s=96&d=mm&r=g\",\"caption\":\"Adarsh Menon\"},\"description\":\"Adarsh is a tech &amp; data science enthusiast. In his own words, \u201cI make websites and teach machines to predict stuff. I also make YouTube videos \u2014 https:\\\/\\\/www.youtube.com\\\/adarshmenon\\\"\",\"url\":\"https:\\\/\\\/aiplanet.com\\\/blog\\\/author\\\/adarsh_menon\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Tutorial on Linear Regression using Gradient Descent - AI Planet","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/aiplanet.com\/blog\/tutorial-on-linear-regression-using-gradient-descent\/","og_locale":"en_US","og_type":"article","og_title":"Tutorial on Linear Regression using Gradient Descent - AI Planet","og_description":"This article talks about how the gradient descent algorithm works and describes the implementation from scratch in python.","og_url":"https:\/\/aiplanet.com\/blog\/tutorial-on-linear-regression-using-gradient-descent\/","og_site_name":"AI Planet","article_publisher":"https:\/\/www.facebook.com\/aiplanet\/","article_published_time":"2020-04-13T14:51:52+00:00","article_modified_time":"2022-11-15T10:09:05+00:00","og_image":[{"url":"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2020\/04\/LR3_1.gif","type":"","width":"","height":""}],"author":"Adarsh Menon","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Adarsh Menon","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/aiplanet.com\/blog\/tutorial-on-linear-regression-using-gradient-descent\/#article","isPartOf":{"@id":"https:\/\/aiplanet.com\/blog\/tutorial-on-linear-regression-using-gradient-descent\/"},"author":{"name":"Adarsh Menon","@id":"https:\/\/aiplanet.com\/blog\/#\/schema\/person\/b121996cdbe68ef54fbc4683ff368a27"},"headline":"Tutorial on Linear Regression using Gradient Descent","datePublished":"2020-04-13T14:51:52+00:00","dateModified":"2022-11-15T10:09:05+00:00","mainEntityOfPage":{"@id":"https:\/\/aiplanet.com\/blog\/tutorial-on-linear-regression-using-gradient-descent\/"},"wordCount":896,"commentCount":0,"publisher":{"@id":"https:\/\/aiplanet.com\/blog\/#organization"},"image":{"@id":"https:\/\/aiplanet.com\/blog\/tutorial-on-linear-regression-using-gradient-descent\/#primaryimage"},"thumbnailUrl":"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2020\/04\/LR3_1.gif","keywords":["datascience","gradient descent","linear regression","machine learning","python"],"articleSection":["datascience"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/aiplanet.com\/blog\/tutorial-on-linear-regression-using-gradient-descent\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/aiplanet.com\/blog\/tutorial-on-linear-regression-using-gradient-descent\/","url":"https:\/\/aiplanet.com\/blog\/tutorial-on-linear-regression-using-gradient-descent\/","name":"Tutorial on Linear Regression using Gradient Descent - AI Planet","isPartOf":{"@id":"https:\/\/aiplanet.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/aiplanet.com\/blog\/tutorial-on-linear-regression-using-gradient-descent\/#primaryimage"},"image":{"@id":"https:\/\/aiplanet.com\/blog\/tutorial-on-linear-regression-using-gradient-descent\/#primaryimage"},"thumbnailUrl":"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2020\/04\/LR3_1.gif","datePublished":"2020-04-13T14:51:52+00:00","dateModified":"2022-11-15T10:09:05+00:00","breadcrumb":{"@id":"https:\/\/aiplanet.com\/blog\/tutorial-on-linear-regression-using-gradient-descent\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/aiplanet.com\/blog\/tutorial-on-linear-regression-using-gradient-descent\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/aiplanet.com\/blog\/tutorial-on-linear-regression-using-gradient-descent\/#primaryimage","url":"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2020\/04\/LR3_1.gif","contentUrl":"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2020\/04\/LR3_1.gif"},{"@type":"BreadcrumbList","@id":"https:\/\/aiplanet.com\/blog\/tutorial-on-linear-regression-using-gradient-descent\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/aiplanet.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Tutorial on Linear Regression using Gradient Descent"}]},{"@type":"WebSite","@id":"https:\/\/aiplanet.com\/blog\/#website","url":"https:\/\/aiplanet.com\/blog\/","name":"AI Planet, Formerly DPhi","description":"AI Planet (formerly DPhi) is a global ecosystem that aims to educate and empower individuals and organizations to build and utilize artificial intelligence (AI). With a community of over 300,000 AI specialists and enthusiasts, we offer a range of products and have helped drive innovative solutions for various industries. Our ultimate goal is to make AI education accessible to everyone and use AI to tackle important business and social challenges.","publisher":{"@id":"https:\/\/aiplanet.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/aiplanet.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/aiplanet.com\/blog\/#organization","name":"AI Planet, Formerly DPhi","url":"https:\/\/aiplanet.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/aiplanet.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2022\/11\/Size48-Large-1.png","contentUrl":"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2022\/11\/Size48-Large-1.png","width":48,"height":48,"caption":"AI Planet, Formerly DPhi"},"image":{"@id":"https:\/\/aiplanet.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/aiplanet\/","https:\/\/www.instagram.com\/aiplanet_community\/","https:\/\/www.linkedin.com\/company\/aiplanet\/","https:\/\/www.youtube.com\/@aiplanet"]},{"@type":"Person","@id":"https:\/\/aiplanet.com\/blog\/#\/schema\/person\/b121996cdbe68ef54fbc4683ff368a27","name":"Adarsh Menon","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/c60cd7eab96e2afd47ba36714163d1f75f4f470b5a5da376a761e1a0f74b12bf?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/c60cd7eab96e2afd47ba36714163d1f75f4f470b5a5da376a761e1a0f74b12bf?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c60cd7eab96e2afd47ba36714163d1f75f4f470b5a5da376a761e1a0f74b12bf?s=96&d=mm&r=g","caption":"Adarsh Menon"},"description":"Adarsh is a tech &amp; data science enthusiast. In his own words, \u201cI make websites and teach machines to predict stuff. I also make YouTube videos \u2014 https:\/\/www.youtube.com\/adarshmenon\"","url":"https:\/\/aiplanet.com\/blog\/author\/adarsh_menon\/"}]}},"_links":{"self":[{"href":"https:\/\/aiplanet.com\/blog\/wp-json\/wp\/v2\/posts\/501","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/aiplanet.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/aiplanet.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/aiplanet.com\/blog\/wp-json\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"https:\/\/aiplanet.com\/blog\/wp-json\/wp\/v2\/comments?post=501"}],"version-history":[{"count":4,"href":"https:\/\/aiplanet.com\/blog\/wp-json\/wp\/v2\/posts\/501\/revisions"}],"predecessor-version":[{"id":4961,"href":"https:\/\/aiplanet.com\/blog\/wp-json\/wp\/v2\/posts\/501\/revisions\/4961"}],"wp:attachment":[{"href":"https:\/\/aiplanet.com\/blog\/wp-json\/wp\/v2\/media?parent=501"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/aiplanet.com\/blog\/wp-json\/wp\/v2\/categories?post=501"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/aiplanet.com\/blog\/wp-json\/wp\/v2\/tags?post=501"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}