<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Shreyy]]></title><description><![CDATA[Exploring software engineering, applied AI, and systems design. Understanding how things work, questioning assumptions, and approaching problems from first principles. A space to document what I learn and build along the way.]]></description><link>https://shreyy.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Fri, 04 Dec 2026 21:50:17 GMT</lastBuildDate><atom:link href="https://shreyy.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[The Intuition Behind the “Hello World” of Machine Learning]]></title><description><![CDATA[Learn how linear regression works: weights, bias, MSE cost function, and gradient descent, explained intuitively as the Hello World of ML.]]></description><link>https://shreyy.hashnode.dev/the-intuition-behind-the-hello-world-of-machine-learning</link><guid isPermaLink="true">https://shreyy.hashnode.dev/the-intuition-behind-the-hello-world-of-machine-learning</guid><category><![CDATA[Machine Learning]]></category><category><![CDATA[linearregression]]></category><category><![CDATA[Gradient-Descent ]]></category><category><![CDATA[Cost function]]></category><category><![CDATA[Supervised learning]]></category><dc:creator><![CDATA[Shreyas Sharma]]></dc:creator><pubDate>Fri, 27 Nov 2026 13:07:39 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6b09794e4409f8df46da1451/d9c7aa29-82cf-496f-b4ef-bb2ce12d1d8b.webp" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>If there’s a superpower humans have chased throughout history, it’s the ability to peek into the future. From astrology and tarot cards to omens and prophecies, numerous civilizations searched for ways to know what lay ahead. Time moved forward, and as our understanding of the world evolved, we stopped looking at the stars to look at the data instead.</p>
<p>Machine learning isn’t a magical wand that lets us see the future, but it can uncover patterns in observations and use them to make predictions that are surprisingly accurate. At the heart of this lies Linear Regression, a fairly simple algorithm that offers us a mathematical framework to answer the fundamental question: “Given what I already know, can I predict what comes next?”</p>
<h3><strong>Linear Regression existed before Machine Learning</strong></h3>
<p>Machine learning has become a buzzword in recent decades, and will probably remain so for some time. However, linear regression was developed as a statistical method for learning the relationship between variables much before machine learning existed.</p>
<p>It was first used to predict the height of offspring and then went on to gain popularity before the emergence of machine learning. It’s both a statistical algorithm and a machine learning algorithm that has been around for more than 200 years. The literal meaning of the term regression is going backwards, but in statistics it refers to estimating the continuous relationship between two or more variables. It is a type of supervised learning algorithm where labelled datasets are used to train the models.</p>
<img src="https://cdn.hashnode.com/uploads/covers/6b09794e4409f8df46da1451/37c78109-cc97-4acd-8ffc-a94168f24b59.png" alt="" style="display:block;margin:0 auto" />

<h3><strong>Finding Relationships in Data</strong></h3>
<p>Linear Regression works on the assumption that there exists a linear relationship between the input variable x, called the feature, and the output variable y, called the target. It tries to map one or more features to the target variable using an affine function, defined as:</p>
<img src="https://cdn.hashnode.com/uploads/covers/6b09794e4409f8df46da1451/0374e5e8-c387-4862-9979-6f990797fadf.png" alt="" style="display:block;margin:0 auto" />

<p>Here, w is the slope of the line, called the weight, and b is the intercept, called the bias. The weight determines how sensitive our prediction is to changes in x, and bias gives us the predicted value when x = 0.</p>
<img src="https://cdn.hashnode.com/uploads/covers/6b09794e4409f8df46da1451/6f7c2923-eb8c-4fd4-8e84-570342d0bb60.png" alt="" style="display:block;margin:0 auto" />

<p>The red line is our hypothesis trying to predict the price of a house based on the area, and the scattered yellow points are the training examples that we had. Notice how the line doesn’t pass through all the yellow points, indicating that our prediction will inevitably contain some error.</p>
<p>To fit this line, we need the right values for w and b that’ll make our prediction closer to the target. For this, we’ll devise a way to figure out how wrong our prediction is and then update the values of w and b iteratively. Since we’re dealing with a training set and not just one data point, the individual errors can be combined into a single quantity known as the cost function.</p>
<img src="https://cdn.hashnode.com/uploads/covers/6b09794e4409f8df46da1451/058ade7c-617c-4cdd-85fa-67e5fcfd604f.png" alt="" style="display:block;margin:0 auto" />

<p>In linear regression, we use the Mean Squared Error (MSE), which squares the error terms before averaging them. Squaring the error terms helps us penalize larger mistakes in prediction more heavily, pushing the model to find a line that fits the data more accurately.</p>
<p><strong>Note:</strong> We divided our cost function with <code>m</code> to average the error across the training examples and then included factor of <code>1/2</code> to make the calculations cleaner.</p>
<h3><strong>Optimization is the Way</strong></h3>
<p>Since the cost function depends on the values of w and b, we need to find the parameters that will help us minimize the cost, and this makes our goal an optimization problem. I think we already have an idea about how to achieve this feat, and that is by iterating the values of w and b till we reach the optimal point. The question is how do we get there?</p>
<p>This is where Gradient Descent comes to the rescue. It’s an optimization algorithm used by multiple machine learning models that iteratively keeps adjusting the parameters until the minimum cost function state is achieved.</p>
<img src="https://cdn.hashnode.com/uploads/covers/6b09794e4409f8df46da1451/75a650e5-e28c-41cf-b969-e87501c95cad.png" alt="" style="display:block;margin:0 auto" />

<p>Before we get into gradient descent, we need to first unlock what a gradient is. A gradient is a measure of how sensitive a function is to small changes in its parameters. In mathematical terms, it’s a vector of partial derivatives that tells us how much the cost function changes on updating the values of parameters.</p>
<p>The partial derivative of the cost function with respect to the parameters gives us:</p>
<img src="https://cdn.hashnode.com/uploads/covers/6b09794e4409f8df46da1451/ac37a4dc-6398-4dfb-b558-bc96b3b2f892.png" alt="" style="display:block;margin:0 auto" />

<p>We begin with random values of w and b, often taken to be zero in simple regression models, and then repeatedly update them by taking small steps like walking down a hill. The steps in the beginning could be large, depending upon how steep the cost function is, but they become smaller as we approach the minimum, and the parameters gradually converge to their optimal values. Mathematically, the parameter updates can be expressed as:</p>
<img src="https://cdn.hashnode.com/uploads/covers/6b09794e4409f8df46da1451/32021d37-aab4-4664-acdd-0f316d86cee7.png" alt="" style="display:block;margin:0 auto" />

<p>Here, α (alpha) is the learning rate, which is used to determine the size of the step we take after each iteration. A high learning rate takes larger steps but also risks overshooting the minimum, whereas a low learning rate ensures precise steps but increases the number of iterations required to reach the optimum.</p>
<h3><strong>When does Linear Regression Work Well?</strong></h3>
<p>For linear regression to work well, the relationship between the input and the output variable should be approximately linear. The simplicity and computational efficiency it provides make it an ideal model for many predictive tasks. You can try it yourself on different datasets to understand the relationship between two or more variables, like how the economic growth of a country is linked to the electricity consumption, and so on.</p>
<p>There are known limitations to linear regression as well. The real world hardly offers a linear relationship between the feature and target variables; that is why we have other algorithms and models to look at. This, however, doesn’t change the fact that linear regression is one of the fundamental ideas in machine learning and can be used as a lens to understand other complex models such as decision trees, neural networks, etc.</p>
<p>It’s not merely about fitting a line to data, but developing an intuition for how machines learn from experience and improve through optimization.</p>
]]></content:encoded></item></channel></rss>