<?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" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Bashir Sadat on Medium]]></title>
        <description><![CDATA[Stories by Bashir Sadat on Medium]]></description>
        <link>https://medium.com/@bashirsadat?source=rss-c1af253771c2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Oixqyny1ZL7kzqfA.</url>
            <title>Stories by Bashir Sadat on Medium</title>
            <link>https://medium.com/@bashirsadat?source=rss-c1af253771c2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 01:21:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@bashirsadat/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Demystifying Regularization in Linear Regression: A Step-by-Step Guide]]></title>
            <link>https://medium.com/@bashirsadat/demystifying-regularization-in-linear-regression-a-step-by-step-guide-235ad0de0bb1?source=rss-c1af253771c2------2</link>
            <guid isPermaLink="false">https://medium.com/p/235ad0de0bb1</guid>
            <category><![CDATA[regularization]]></category>
            <category><![CDATA[mls]]></category>
            <dc:creator><![CDATA[Bashir Sadat]]></dc:creator>
            <pubDate>Thu, 17 Oct 2024 14:11:40 GMT</pubDate>
            <atom:updated>2024-10-17T14:11:40.952Z</atom:updated>
            <content:encoded><![CDATA[<h3>By Bashir Sadat</h3><p><strong>Introduction</strong></p><p>Have you ever wondered how computers can predict housing prices, stock trends, or even recommend movies you might like? One of the fundamental techniques behind these predictions is <strong>linear regression</strong>. In this guide, we’ll explore linear regression with two features and dive into the concept of <strong>regularization</strong>, a technique used to improve model predictions and prevent overfitting.</p><p>Whether you’re new to machine learning or just curious about how these models work, this guide is for you. We’ll walk through a simple example step by step, explaining each concept in plain language. No heavy math or prior experience required!</p><h3>Table of Contents</h3><ol><li><a href="#1-understanding-linear-regression">Understanding Linear Regression</a></li><li><a href="#2-our-sample-data">Our Sample Data</a></li><li><a href="#3-step-1-initializing-the-model">Step 1: Initializing the Model</a></li><li><a href="#4-step-2-making-initial-predictions">Step 2: Making Initial Predictions</a></li><li><a href="#5-step-3-calculating-the-initial-loss">Step 3: Calculating the Initial Loss</a></li><li><a href="#6-step-4-updating-the-model-with-gradient-descent">Step 4: Updating the Model with Gradient Descent</a></li><li><a href="#7-step-5-making-predictions-after-the-update">Step 5: Making Predictions After the Update</a></li><li><a href="#8-step-6-calculating-loss-after-the-update">Step 6: Calculating Loss After the Update</a></li><li><a href="#9-step-7-introducing-regularization">Step 7: Introducing Regularization</a></li></ol><ul><li><a href="#part-a-l1-regularization-lasso">Part A: L1 Regularization (Lasso)</a></li><li><a href="#part-b-l2-regularization-ridge">Part B: L2 Regularization (Ridge)</a></li></ul><p><a href="#10-step-8-comparing-the-effects-of-regularization">10. Step 8: Comparing the Effects of Regularization</a></p><p><a href="#11-key-takeaways">11. Key Takeaways</a></p><p><a href="#12-conclusion">12. Conclusion</a></p><h3>1. Understanding Linear Regression</h3><h3>What is Linear Regression?</h3><p>Linear regression is a statistical method used to model the relationship between one or more <strong>independent variables</strong> (features) and a <strong>dependent variable</strong> (target). The goal is to find the best-fitting straight line (or hyperplane in higher dimensions) that predicts the target variable based on the input features.</p><h3>Our Model</h3><p>In this guide, we’ll build a linear regression model with two features:</p><ul><li><strong>Feature 1 (x1x_1x1​)</strong></li><li><strong>Feature 2 (x2x_2x2​)</strong></li></ul><p>The model aims to predict a target variable yyy using the following equation:</p><p>y^=θ0+θ1x1+θ2x2\hat{y} = \theta_0 + \theta_1 x_1 + \theta_2 x_2y^​=θ0​+θ1​x1​+θ2​x2​</p><p>Where:</p><ul><li>y^\hat{y}y^​: Predicted value of yyy</li><li>θ0\theta_0θ0​: Intercept (also known as the bias term)</li><li>θ1\theta_1θ1​, θ2\theta_2θ2​: Coefficients (weights) for x1x_1x1​ and x2x_2x2​</li></ul><h3>2. Our Sample Data</h3><p>Let’s consider a simple dataset with 4 observations:</p><p>Observationx1x_1x1​x2x_2x2​yyy11252216330744–18</p><p>Our goal is to find the best values for θ0\theta_0θ0​, θ1\theta_1θ1​, and θ2\theta_2θ2​ that minimize the difference between our predictions y^\hat{y}y^​ and the actual values yyy.</p><h3>3. Step 1: Initializing the Model</h3><p>Before we start, we need to initialize our coefficients (weights). We’ll start with some initial guesses:</p><ul><li><strong>θ0=0\theta_0 = 0θ0​=0</strong> (Initial intercept)</li><li><strong>θ1=1\theta_1 = 1θ1​=1</strong> (Initial weight for x1x_1x1​)</li><li><strong>θ2=1\theta_2 = 1θ2​=1</strong> (Initial weight for x2x_2x2​)</li></ul><h3>4. Step 2: Making Initial Predictions</h3><p>Using our initial coefficients, we’ll calculate the predicted values y^\hat{y}y^​ for each observation.</p><h3>Calculations:</h3><ol><li><strong>Observation 1:</strong></li><li>y¹=θ0+θ1x11+θ2x12=0+(1×1)+(1×2)=3\hat{y}_1 = \theta_0 + \theta_1 x_{11} + \theta_2 x_{12} = 0 + (1 \times 1) + (1 \times 2) = 3y^​1​=θ0​+θ1​x11​+θ2​x12​=0+(1×1)+(1×2)=3</li><li><strong>Observation 2:</strong></li><li>y²=0+(1×2)+(1×1)=3\hat{y}_2 = 0 + (1 \times 2) + (1 \times 1) = 3y^​2​=0+(1×2)+(1×1)=3</li><li><strong>Observation 3:</strong></li><li>y³=0+(1×3)+(1×0)=3\hat{y}_3 = 0 + (1 \times 3) + (1 \times 0) = 3y^​3​=0+(1×3)+(1×0)=3</li><li><strong>Observation 4:</strong></li><li>y⁴=0+(1×4)+(1×−1)=3\hat{y}_4 = 0 + (1 \times 4) + (1 \times -1) = 3y^​4​=0+(1×4)+(1×−1)=3</li></ol><p><strong>Summary:</strong></p><p>ObservationActual yyyPredicted y^\hat{y}y^​153263373483</p><h3>5. Step 3: Calculating the Initial Loss</h3><p>The <strong>loss function</strong> measures how well our model’s predictions match the actual data. We’ll use the <strong>Mean Squared Error (MSE)</strong>, which calculates the average squared difference between the predicted and actual values.</p><h3>MSE Formula:</h3><p>MSE=1n∑i=1n(yi−y^i)2\text{MSE} = \frac{1}{n} \sum_{i=1}^{n} (y_i — \hat{y}_i)²MSE=n1​i=1∑n​(yi​−y^​i​)2</p><p>Where:</p><ul><li>nnn: Number of observations (here, n=4n = 4n=4)</li><li>yiy_iyi​: Actual value</li><li>y^i\hat{y}_iy^​i​: Predicted value</li></ul><h3>Calculations:</h3><ol><li><strong>Observation 1:</strong></li><li>(y1−y¹)2=(5−3)2=4(y_1 — \hat{y}_1)² = (5–3)² = 4(y1​−y^​1​)2=(5−3)2=4</li><li><strong>Observation 2:</strong></li><li>(6−3)2=9(6–3)² = 9(6−3)2=9</li><li><strong>Observation 3:</strong></li><li>(7−3)2=16(7–3)² = 16(7−3)2=16</li><li><strong>Observation 4:</strong></li><li>(8−3)2=25(8–3)² = 25(8−3)2=25</li></ol><p><strong>Total Loss:</strong></p><p>MSE=14(4+9+16+25)=14(54)=13.5\text{MSE} = \frac{1}{4} (4 + 9 + 16 + 25) = \frac{1}{4} (54) = 13.5MSE=41​(4+9+16+25)=41​(54)=13.5</p><h3>6. Step 4: Updating the Model with Gradient Descent</h3><p>To improve our model, we’ll adjust the coefficients using an optimization algorithm called <strong>Gradient Descent</strong>.</p><h3>What is Gradient Descent?</h3><p>Gradient Descent is a method to find the minimum of a function. In our case, we want to minimize the loss function. It works by calculating the gradient (slope) of the loss function and moving in the opposite direction.</p><h3>Learning Rate (α\alphaα)</h3><ul><li>The learning rate determines the size of the steps we take towards the minimum.</li><li>We’ll use α=0.1\alpha = 0.1α=0.1.</li></ul><h3>Calculating the Gradients</h3><p>The gradient of the loss function with respect to each coefficient is:</p><p>∂MSE∂θj=−2n∑i=1n(yi−y^i)xij\frac{\partial \text{MSE}}{\partial \theta_j} = -\frac{2}{n} \sum_{i=1}^{n} (y_i — \hat{y}_i) x_{ij}∂θj​∂MSE​=−n2​i=1∑n​(yi​−y^​i​)xij​</p><p>Where:</p><ul><li>xijx_{ij}xij​: The jthj^{th}jth feature of the ithi^{th}ith observation.</li></ul><h4>For θ0\theta_0θ0​ (Intercept):</h4><p>Since θ0\theta_0θ0​ is not multiplied by a feature, xi0=1x_{i0} = 1xi0​=1 for all iii.</p><p>∂MSE∂θ0=−2n∑i=1n(yi−y^i)\frac{\partial \text{MSE}}{\partial \theta_0} = -\frac{2}{n} \sum_{i=1}^{n} (y_i — \hat{y}_i)∂θ0​∂MSE​=−n2​i=1∑n​(yi​−y^​i​)</p><h4>Calculations:</h4><ul><li><strong>Residuals (yi−y^iy_i — \hat{y}_iyi​−y^​i​):</strong></li><li>Observationyi−y^iy_i — \hat{y}_iyi​−y^​i​12233445</li><li><strong>Sum of Residuals:</strong></li><li>∑i=14(yi−y^i)=2+3+4+5=14\sum_{i=1}^{4} (y_i — \hat{y}_i) = 2 + 3 + 4 + 5 = 14i=1∑4​(yi​−y^​i​)=2+3+4+5=14</li><li><strong>Gradient for θ0\theta_0θ0​:</strong></li><li>∂MSE∂θ0=−24×14=−7\frac{\partial \text{MSE}}{\partial \theta_0} = -\frac{2}{4} \times 14 = -7∂θ0​∂MSE​=−42​×14=−7</li><li><strong>Gradient for θ1\theta_1θ1​:</strong></li><li>∂MSE∂θ1=−24∑i=14(yi−y^i)xi1\frac{\partial \text{MSE}}{\partial \theta_1} = -\frac{2}{4} \sum_{i=1}^{4} (y_i — \hat{y}_i) x_{i1}∂θ1​∂MSE​=−42​i=1∑4​(yi​−y^​i​)xi1​</li><li>Calculating (yi−y^i)xi1(y_i — \hat{y}_i) x_{i1}(yi​−y^​i​)xi1​:</li><li>Observationxi1x_{i1}xi1​(yi−y^i)xi1(y_i — \hat{y}_i) x_{i1}(yi​−y^​i​)xi1​11222633124420</li><li>Sum:</li><li>∑i=14(yi−y^i)xi1=2+6+12+20=40\sum_{i=1}^{4} (y_i — \hat{y}_i) x_{i1} = 2 + 6 + 12 + 20 = 40i=1∑4​(yi​−y^​i​)xi1​=2+6+12+20=40</li><li>Gradient:</li><li>∂MSE∂θ1=−24×40=−20\frac{\partial \text{MSE}}{\partial \theta_1} = -\frac{2}{4} \times 40 = -20∂θ1​∂MSE​=−42​×40=−20</li><li><strong>Gradient for θ2\theta_2θ2​:</strong></li><li>Similar calculations yield:</li><li>∂MSE∂θ2=−1\frac{\partial \text{MSE}}{\partial \theta_2} = -1∂θ2​∂MSE​=−1</li></ul><h3>Updating the Coefficients</h3><p>Using the gradient descent update rule:</p><p>θjnew=θjold−α∂MSE∂θj\theta_j^{\text{new}} = \theta_j^{\text{old}} — \alpha \frac{\partial \text{MSE}}{\partial \theta_j}θjnew​=θjold​−α∂θj​∂MSE​</p><ul><li><strong>Update θ0\theta_0θ0​:</strong></li><li>θ0=0−0.1×(−7)=0.7\theta_0 = 0–0.1 \times (-7) = 0.7θ0​=0−0.1×(−7)=0.7</li><li><strong>Update θ1\theta_1θ1​:</strong></li><li>θ1=1−0.1×(−20)=3\theta_1 = 1–0.1 \times (-20) = 3θ1​=1−0.1×(−20)=3</li><li><strong>Update θ2\theta_2θ2​:</strong></li><li>θ2=1−0.1×(−1)=1.1\theta_2 = 1–0.1 \times (-1) = 1.1θ2​=1−0.1×(−1)=1.1</li></ul><h3>7. Step 5: Making Predictions After the Update</h3><p>Using the updated coefficients, we calculate the new predicted values.</p><h3>Calculations:</h3><ol><li><strong>Observation 1:</strong></li><li>y¹=0.7+(3×1)+(1.1×2)=5.9\hat{y}_1 = 0.7 + (3 \times 1) + (1.1 \times 2) = 5.9y^​1​=0.7+(3×1)+(1.1×2)=5.9</li><li><strong>Observation 2:</strong></li><li>y²=0.7+(3×2)+(1.1×1)=7.8\hat{y}_2 = 0.7 + (3 \times 2) + (1.1 \times 1) = 7.8y^​2​=0.7+(3×2)+(1.1×1)=7.8</li><li><strong>Observation 3:</strong></li><li>y³=0.7+(3×3)+(1.1×0)=9.7\hat{y}_3 = 0.7 + (3 \times 3) + (1.1 \times 0) = 9.7y^​3​=0.7+(3×3)+(1.1×0)=9.7</li><li><strong>Observation 4:</strong></li><li>y⁴=0.7+(3×4)+(1.1×−1)=11.6\hat{y}_4 = 0.7 + (3 \times 4) + (1.1 \times -1) = 11.6y^​4​=0.7+(3×4)+(1.1×−1)=11.6</li></ol><h3>8. Step 6: Calculating Loss After the Update</h3><h3>Calculations:</h3><ol><li><strong>Observation 1:</strong></li><li>(5−5.9)2=0.81(5–5.9)² = 0.81(5−5.9)2=0.81</li><li><strong>Observation 2:</strong></li><li>(6−7.8)2=3.24(6–7.8)² = 3.24(6−7.8)2=3.24</li><li><strong>Observation 3:</strong></li><li>(7−9.7)2=7.29(7–9.7)² = 7.29(7−9.7)2=7.29</li><li><strong>Observation 4:</strong></li><li>(8−11.6)2=12.96(8–11.6)² = 12.96(8−11.6)2=12.96</li></ol><p><strong>Total Loss:</strong></p><p>MSE=14(0.81+3.24+7.29+12.96)=6.075\text{MSE} = \frac{1}{4} (0.81 + 3.24 + 7.29 + 12.96) = 6.075MSE=41​(0.81+3.24+7.29+12.96)=6.075</p><p><strong>Observation:</strong> The loss decreased from <strong>13.5</strong> to <strong>6.075</strong>, indicating our model is improving.</p><h3>9. Step 7: Introducing Regularization</h3><h3>Why Regularization?</h3><p>Regularization is a technique used to prevent <strong>overfitting</strong>, which happens when a model learns the training data too well, including the noise, and doesn’t perform well on new data. It does this by adding a penalty to the loss function for large coefficients.</p><p>We’ll explore two types of regularization:</p><ul><li><strong>L1 Regularization (Lasso)</strong></li><li><strong>L2 Regularization (Ridge)</strong></li></ul><h3>Part A: L1 Regularization (Lasso)</h3><h4>Modified Loss Function</h4><p>LossL1=MSE+λ∑j=02∣θj∣\text{Loss}_{\text{L1}} = \text{MSE} + \lambda \sum_{j=0}^{2} |\theta_j|LossL1​=MSE+λj=0∑2​∣θj​∣</p><ul><li>λ\lambdaλ: Regularization parameter (we’ll use λ=0.1\lambda = 0.1λ=0.1)</li><li>∣θj∣|\theta_j|∣θj​∣: Absolute value of coefficient θj\theta_jθj​</li></ul><h4>Calculating the Regularization Term</h4><p>Using the updated coefficients:</p><p>∑j=02∣θj∣=∣0.7∣+∣3∣+∣1.1∣=4.8\sum_{j=0}^{2} |\theta_j| = |0.7| + |3| + |1.1| = 4.8j=0∑2​∣θj​∣=∣0.7∣+∣3∣+∣1.1∣=4.8</p><p>Regularization Term:</p><p>0.1×4.8=0.480.1 \times 4.8 = 0.480.1×4.8=0.48</p><h4>Total Loss with L1 Regularization</h4><p>LossL1=6.075+0.48=6.555\text{Loss}_{\text{L1}} = 6.075 + 0.48 = 6.555LossL1​=6.075+0.48=6.555</p><h4>Updating Coefficients with L1 Regularization</h4><p>The gradient with L1 regularization is:</p><p>∂LossL1∂θj=−2n∑i=1n(yi−y^i)xij+λ⋅sign(θj)\frac{\partial \text{Loss}_{\text{L1}}}{\partial \theta_j} = -\frac{2}{n} \sum_{i=1}^{n} (y_i — \hat{y}_i) x_{ij} + \lambda \cdot \text{sign}(\theta_j)∂θj​∂LossL1​​=−n2​i=1∑n​(yi​−y^​i​)xij​+λ⋅sign(θj​)</p><ul><li><strong>sign(θj)\text{sign}(\theta_j)sign(θj​)</strong>: The sign function of θj\theta_jθj​</li><li>If θj&gt;0\theta_j &gt; 0θj​&gt;0, sign(θj)=1\text{sign}(\theta_j) = 1sign(θj​)=1</li><li>If θj&lt;0\theta_j &lt; 0θj​&lt;0, sign(θj)=−1\text{sign}(\theta_j) = -1sign(θj​)=−1</li><li>If θj=0\theta_j = 0θj​=0, sign(θj)=0\text{sign}(\theta_j) = 0sign(θj​)=0</li></ul><p><strong>Updated Gradients:</strong></p><ul><li><strong>For θ0\theta_0θ0​:</strong></li><li>∂LossL1∂θ0=4.6\frac{\partial \text{Loss}_{\text{L1}}}{\partial \theta_0} = 4.6∂θ0​∂LossL1​​=4.6</li><li><strong>For θ1\theta_1θ1​:</strong></li><li>∂LossL1∂θ1=13.6\frac{\partial \text{Loss}_{\text{L1}}}{\partial \theta_1} = 13.6∂θ1​∂LossL1​​=13.6</li><li><strong>For θ2\theta_2θ2​:</strong></li><li>∂LossL1∂θ2=0.1\frac{\partial \text{Loss}_{\text{L1}}}{\partial \theta_2} = 0.1∂θ2​∂LossL1​​=0.1</li></ul><p><strong>Updating the Coefficients:</strong></p><ul><li><strong>θ0=0.7−0.1×4.6=0.24\theta_0 = 0.7–0.1 \times 4.6 = 0.24θ0​=0.7−0.1×4.6=0.24</strong></li><li><strong>θ1=3−0.1×13.6=1.64\theta_1 = 3–0.1 \times 13.6 = 1.64θ1​=3−0.1×13.6=1.64</strong></li><li><strong>θ2=1.1−0.1×0.1=1.09\theta_2 = 1.1–0.1 \times 0.1 = 1.09θ2​=1.1−0.1×0.1=1.09</strong></li></ul><h3>Part B: L2 Regularization (Ridge)</h3><h4>Modified Loss Function</h4><p>LossL2=MSE+λ∑j=02θj2\text{Loss}_{\text{L2}} = \text{MSE} + \lambda \sum_{j=0}^{2} \theta_j²LossL2​=MSE+λj=0∑2​θj2​</p><h4>Calculating the Regularization Term</h4><p>∑j=02θj2=(0.7)2+(3)2+(1.1)2=10.7\sum_{j=0}^{2} \theta_j² = (0.7)² + (3)² + (1.1)² = 10.7j=0∑2​θj2​=(0.7)2+(3)2+(1.1)2=10.7</p><p>Regularization Term:</p><p>0.1×10.7=1.070.1 \times 10.7 = 1.070.1×10.7=1.07</p><h4>Total Loss with L2 Regularization</h4><p>LossL2=6.075+1.07=7.145\text{Loss}_{\text{L2}} = 6.075 + 1.07 = 7.145LossL2​=6.075+1.07=7.145</p><h4>Updating Coefficients with L2 Regularization</h4><p>The gradient with L2 regularization is:</p><p>∂LossL2∂θj=−2n∑i=1n(yi−y^i)xij+2λθj\frac{\partial \text{Loss}_{\text{L2}}}{\partial \theta_j} = -\frac{2}{n} \sum_{i=1}^{n} (y_i — \hat{y}_i) x_{ij} + 2\lambda \theta_j∂θj​∂LossL2​​=−n2​i=1∑n​(yi​−y^​i​)xij​+2λθj​</p><p><strong>Updated Gradients:</strong></p><ul><li><strong>For θ0\theta_0θ0​:</strong></li><li>∂LossL2∂θ0=4.64\frac{\partial \text{Loss}_{\text{L2}}}{\partial \theta_0} = 4.64∂θ0​∂LossL2​​=4.64</li><li><strong>For θ1\theta_1θ1​:</strong></li><li>∂LossL2∂θ1=14.1\frac{\partial \text{Loss}_{\text{L2}}}{\partial \theta_1} = 14.1∂θ1​∂LossL2​​=14.1</li><li><strong>For θ2\theta_2θ2​:</strong></li><li>∂LossL2∂θ2=0.22\frac{\partial \text{Loss}_{\text{L2}}}{\partial \theta_2} = 0.22∂θ2​∂LossL2​​=0.22</li></ul><p><strong>Updating the Coefficients:</strong></p><ul><li><strong>θ0=0.7−0.1×4.64=0.236\theta_0 = 0.7–0.1 \times 4.64 = 0.236θ0​=0.7−0.1×4.64=0.236</strong></li><li><strong>θ1=3−0.1×14.1=1.59\theta_1 = 3–0.1 \times 14.1 = 1.59θ1​=3−0.1×14.1=1.59</strong></li><li><strong>θ2=1.1−0.1×0.22=1.078\theta_2 = 1.1–0.1 \times 0.22 = 1.078θ2​=1.1−0.1×0.22=1.078</strong></li></ul><h3>10. Step 8: Comparing the Effects of Regularization</h3><p>CoefficientWithout RegularizationWith L1 RegularizationWith L2 Regularizationθ0\theta_0θ0​0.70.240.236θ1\theta_1θ1​31.641.59θ2\theta_2θ2​1.11.091.078</p><h3>Observations:</h3><ul><li><strong>L1 Regularization</strong> tends to reduce some coefficients more aggressively and can set them exactly to zero, effectively selecting features.</li><li><strong>L2 Regularization</strong> reduces coefficients but doesn’t eliminate them, keeping all features in the model.</li></ul><h3>11. Key Takeaways</h3><ul><li><strong>Regularization</strong> helps prevent overfitting by penalizing large coefficients.</li><li><strong>L1 Regularization (Lasso):</strong></li><li>Encourages sparsity (some coefficients become zero).</li><li>Useful for feature selection.</li><li><strong>L2 Regularization (Ridge):</strong></li><li>Shrinks coefficients but keeps all features.</li><li>Useful when all features are expected to contribute to the outcome.</li><li><strong>Choosing λ\lambdaλ:</strong></li><li>Controls the strength of the regularization.</li><li>Can be determined using cross-validation.</li><li><strong>Gradient Descent</strong> is a powerful tool for optimizing models by iteratively updating coefficients to minimize loss.</li></ul><h3>12. Conclusion</h3><p>Understanding linear regression and regularization is essential for building robust machine learning models. Regularization techniques like L1 and L2 help improve model generalization by preventing overfitting. By walking through this example, we hope you’ve gained a clearer understanding of how these concepts work together.</p><p><strong>Feel free to leave comments or ask questions below!</strong></p><p><strong>References:</strong></p><ul><li>An Introduction to Statistical Learning</li><li><a href="https://www.coursera.org/learn/machine-learning">Andrew Ng’s Machine Learning Course on Coursera</a></li></ul><p><em>Did you find this guide helpful? Share it with others who might be interested!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=235ad0de0bb1" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>