<?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" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ Samyukta Hegde - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ Samyukta Hegde - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Wed, 21 Oct 2026 21:34:30 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/author/samyuktashegde/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ How Neural Networks Work: Why Straight Lines Aren't Enough ]]>
                </title>
                <description>
                    <![CDATA[ A straight line equation is a good place to start understanding how a neural network works. It's what we explored in my previous article, How Neural Networks Work – Explained Using the Straight Line E ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-neural-networks-work-why-straight-lines-aren-t-enough/</link>
                <guid isPermaLink="false">6ad7987561e15ba931f3a014</guid>
                
                    <category>
                        <![CDATA[ neural networks ]]>
                    </category>
                
                    <category>
                        <![CDATA[ DeepLearning ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Machine Learning ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Samyukta Hegde ]]>
                </dc:creator>
                <pubDate>Tue, 20 Oct 2026 16:36:05 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/uploads/covers/5e1e335a7a1d3fcc59028c64/0220c2ae-5938-458c-9a87-b97a66c7945e.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>A straight line equation is a good place to start understanding how a neural network works. It's what we explored in my previous article, <a href="https://www.freecodecamp.org/news/neural-networks-explained-using-y-ax-b/">How Neural Networks Work – Explained Using the Straight Line Equation (y=ax+b)</a>.</p>
<p>But, what if the relationship between the input and the output <strong>isn't linear?</strong></p>
<p>We all know that in the real world, the data doesn't always follow a straight line pattern. This is where things start getting interesting: sometimes a single rule isn't enough to describe the relationship between the variables.</p>
<p>That’s where non-linearity comes in. It allows neural networks to capture changing behaviour in data.</p>
<p>In this article, we'll explore the concept of non-linearity that can capture complex relationships in data. Using a simple example, we'll try to understand piecewise linear curves, ReLU functions, S-shaped curves, and sigmoid functions in relation to how they help neural networks learn patterns that a straight line can't describe.</p>
<h2 id="heading-table-of-contents">Table of Contents</h2>
<ul>
<li><p><a href="#heading-prerequisites">Prerequisites</a></p>
</li>
<li><p><a href="#heading-when-a-straight-line-is-enough">When a Straight Line Is Enough</a></p>
</li>
<li><p><a href="#heading-when-a-straight-line-isnt-enough">When a Straight Line Isn't Enough</a></p>
<ul>
<li><p><a href="#heading-piecewise-linear-curve">Piecewise Linear Curve</a></p>
</li>
<li><p><a href="#heading-what-is-a-relu-function">What is a ReLU Function?</a></p>
</li>
<li><p><a href="#heading-s-shaped-curve">S-Shaped Curve</a></p>
</li>
<li><p><a href="#heading-what-is-a-sigmoid-function">What is a Sigmoid Function?</a></p>
</li>
</ul>
</li>
<li><p><a href="#heading-modelling-a-deep-neural-network">Modelling a Deep Neural Network</a></p>
<ul>
<li><p><a href="#heading-predicting-marks-using-relu">Predicting Marks Using ReLU</a></p>
</li>
<li><p><a href="#heading-predicting-passfail-using-relu-and-sigmoid">Predicting Pass/Fail Using ReLU and Sigmoid</a></p>
</li>
</ul>
</li>
<li><p><a href="#heading-final-thoughts">Final Thoughts</a></p>
</li>
</ul>
<h2 id="heading-prerequisites">Prerequisites</h2>
<ul>
<li><p>Basic understanding of linear functions</p>
</li>
<li><p>Familiarity with the concept of deep neural networks</p>
</li>
</ul>
<h2 id="heading-when-a-straight-line-is-enough">When a Straight Line Is Enough</h2>
<p>A straight line equation means that the same rule applies throughout the relationship.</p>
<p>y = ax + b</p>
<pre><code class="language-plaintext">y =&gt; Output variable
x =&gt; Input variable
a =&gt; Amount by which y changes when x changes (slope)
b =&gt; Value of y when x is 0 (y intercept)
</code></pre>
<p>We can look at an example to understand it better.</p>
<p>Ms. Poly is a math teacher who wants to come up with a study plan for her students to help them ace the final exam. She creates a rule of thumb using one factor: the number of hours studied per week. This means that the mark scored by a student is directly proportionate to the hours they spend studying.</p>
<p>Based on her assumption, she comes up with an equation in the form y=ax+b.</p>
<pre><code class="language-plaintext">y =&gt; Marks scored
x =&gt; Number of hours studied
a =&gt; Increase in marks for every hour studied
b =&gt; Minimum marks every student is capable of scoring without studying.
</code></pre>
<p>So, after a quarterly exam, she interviews her students and collects information on how many hours they studied math per week. She creates a table with two columns: number of hours studied (x) per week and marks scored (y) and plots them.</p>
<table>
<thead>
<tr>
<th>Number of Hours Studied</th>
<th>Marks Scored</th>
</tr>
</thead>
<tbody><tr>
<td>0</td>
<td>40</td>
</tr>
<tr>
<td>1</td>
<td>40</td>
</tr>
<tr>
<td>2</td>
<td>41</td>
</tr>
<tr>
<td>3</td>
<td>40</td>
</tr>
<tr>
<td>4</td>
<td>48</td>
</tr>
<tr>
<td>5</td>
<td>58</td>
</tr>
<tr>
<td>6</td>
<td>69</td>
</tr>
<tr>
<td>7</td>
<td>80</td>
</tr>
<tr>
<td>8</td>
<td>80</td>
</tr>
</tbody></table>
<p>But when she tries to apply her simple formula, it doesn't seem to align with the data she collected, proving that real-life data is rarely that straightforward.</p>
<h2 id="heading-when-a-straight-line-isnt-enough">When a Straight Line Isn't Enough</h2>
<p>Ms. Poly observes the graph closely and identifies a few patterns. Students who study for only a few hours may not see much improvement. Once they cross a certain point, their marks begin to increase with additional study. And again after a certain point, the marks remain fairly constant.</p>
<img src="https://cdn.hashnode.com/uploads/covers/681473bee25e59d34a17668b/958b4685-d030-4efa-bc16-50ab231272b3.png" alt="Input Data: Marks scored Vs Study Hours" style="display: block;" width="600" height="400" loading="lazy">

<p>Thus, Ms Poly’s simple straight line equation isn’t enough to describe the relation between number of hours studied (x) per week and marks scored (y).</p>
<p>Instead, it can be divided into three parts,</p>
<pre><code class="language-plaintext">Less than t₁ hours: Marks remain constant
t₁ to t₂ hours: Marks increase with study time
More than t₂ hours: Marks remain constant
</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/681473bee25e59d34a17668b/8c2fb722-bbf7-4ceb-856d-5a352190674d.png" alt="Input Data: Points of Change" style="display: block;" width="600" height="400" loading="lazy">

<p>So, she can have separate equations for each range and write them like this:</p>
<pre><code class="language-plaintext">y = 1st equation, x&lt;t₁
y = 2nd equation, t₁&lt;=x&lt;t₂
y = 3rd equation, x&gt;=t₂
</code></pre>
<p>This example gives us our first glimpse of non-linearity. There are changes in the relationship at specific points, so a single straight line equation is insufficient as the behaviour needs to change at different points.</p>
<p>A simple way to handle this is using a <strong>piecewise linear function</strong>.</p>
<h3 id="heading-piecewise-linear-curve">Piecewise Linear Curve</h3>
<p>To begin with, for simplicity, Ms. Poly decides to consider only two regions.</p>
<pre><code class="language-plaintext">Region1: Hours of study &lt; t₁
Region2: Hours of study &gt;= t₁
</code></pre>
<p>The values in the first region hover around a particular value. Even though they don’t lie perfectly in a line, she can make an approximation and represent that region as a line with slope=0. This indicates that the marks remain roughly the same.</p>
<p>In the second region, there seems to be a positive slope. So she decides on another straight line equation for that steep upward sloping line.</p>
<p>Ms. Poly ends up having two equations for the above graph because one equation can't define it. The rule changes for different ranges as the pattern changes.</p>
<p>So, she can write it like this:</p>
<pre><code class="language-plaintext">y = 1st equation, x&lt;t₁
y = 2nd equation, x&gt;=t₁
</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/681473bee25e59d34a17668b/fe83f93e-2592-4300-b0ab-45dbcac0982c.png" alt="Piecewise Linear Curve" style="display: block;" width="600" height="400" loading="lazy">

<p>Individually, these may seem like straight line equations. But when put together, the overall relationship is no longer a straight line. When x crosses a certain value, the equation changes. This is called <strong>piecewise linear function.</strong> It's a function that's made up of different rules for different ranges of input.</p>
<p>This idea appears in one of the most widely used activation functions in neural networks: <strong>ReLU</strong>.</p>
<h3 id="heading-what-is-a-relu-function">What is a ReLU Function?</h3>
<p>ReLU stands for Rectified Linear Unit. Mathematically, it's this:</p>
<pre><code class="language-plaintext">y = ReLU(x) = max(0,x)
</code></pre>
<p>It keeps positive inputs unchanged and turns negative inputs to zero.</p>
<p>Here too, the individual piece is linear but the overall function is non-linear. So, ReLU is a piecewise linear function that introduces non-linearity.</p>
<p>The graph below shows the ReLU function:</p>
<img src="https://cdn.hashnode.com/uploads/covers/681473bee25e59d34a17668b/589adfcc-fa25-4517-a647-ad40933ea2b4.png" alt="ReLU Function" style="display: block;" width="600" height="400" loading="lazy">

<p>This simple change in behaviour allows a neuron to respond differently to different ranges of input, giving neural networks a way to move beyond a single straight-line relationship.</p>
<h3 id="heading-s-shaped-curve">S-Shaped Curve</h3>
<p>Now, a piecewise linear curve does the job but Ms. Poly sees that there's quite a sharp transition from one region to the other. She had also only considered two regions for simplicity, even though the distribution can be divided into three regions.</p>
<p>So, she draws a smooth curve roughly passing through all the points as shown below:</p>
<img src="https://cdn.hashnode.com/uploads/covers/681473bee25e59d34a17668b/7f1fab69-ca10-43be-83a0-d490fa2de057.png" alt="S-Shaped Curve" style="display: block;" width="600" height="400" loading="lazy">

<p>This shape shows that the marks remain almost the same when a student studies for up to t₁ number of hours. Then, an increase in hours of study from t₁ to t₂, increases the marks scored, so there's a slope. In the end at t₂, it flattens out again. This transition is gradual and continuous unlike the piecewise linear curve which changes directions using simple straight lines.</p>
<p>The curve that Ms Poly drew isn't some random pattern. It can be represented mathematically, too. One of the functions that produces this kind of shape is the <strong>sigmoid</strong> function.</p>
<h3 id="heading-what-is-a-sigmoid-function">What is a Sigmoid Function?</h3>
<p>A sigmoid function is a mathematical formula that takes any real-valued input and maps it to values between 0 and 1. It slowly increases from values close to 0, rises quickly in the middle and gradually levels off at values close to 1.</p>
<pre><code class="language-plaintext">y = σ(x) = 1 / (1 + exp(-x))
</code></pre>
<p>The graph below shows the sigmoid function:</p>
<img src="https://cdn.hashnode.com/uploads/covers/681473bee25e59d34a17668b/851d09c8-34ed-4757-a875-debf18cfd3b8.png" alt="Sigmoid Function" style="display: block;" width="600" height="400" loading="lazy">

<p>The sigmoid function is significant in neural networks because it introduces non-linearity while also restricting the output between 0 and 1. This makes it useful when the output needs to represent a probability such as the likelihood of a student passing an exam. A higher sigmoid output indicates a higher probability of the student passing, and vice versa.</p>
<h2 id="heading-modeling-a-deep-neural-network">Modeling a Deep Neural Network</h2>
<p>Ms Poly should now combine the concepts of linear and non-linear equations to model a deep neural network. She has to take two separate approaches to ,</p>
<ol>
<li><p>Predict the marks scored in the exam</p>
</li>
<li><p>Predict Pass/Fail in the exam</p>
</li>
</ol>
<p>She uses two very simple untrained neural networks with manually chosen weights and biases for each. She is just trying it out to illustrate how calculations work. In reality she wouldn't choose the parameters herself. She would set up the network with weights and biases being learnt during training by repeatedly comparing the predicted values with the actual values and adjusting the parameters to minimise the error.</p>
<h3 id="heading-predicting-marks-using-relu">Predicting Marks Using ReLU</h3>
<h4 id="heading-step-1-set-up-the-network"><strong>Step #1: Set up the network</strong></h4>
<p>Ms Poly has the set up the deep neural network with simple equations in the following way:</p>
<ul>
<li><p>Input Layer: The number of hours studied (x) is received here.</p>
</li>
<li><p>Hidden Layer: Linear transformation and ReLU is applied to the input.</p>
<pre><code class="language-plaintext">z = w₁x + b₁, = x - 3      (w₁=1, b₁=-3)
h = ReLU(z) = max(0, z)
</code></pre>
</li>
<li><p>Output Layer: The marks scored is predicted after applying a linear transformation to the hidden layer's output(h).</p>
<pre><code class="language-plaintext">ŷ = w₂h + b₂ = 10h + 40      (w₂=10, b₂=40)
</code></pre>
</li>
</ul>
<img src="https://cdn.hashnode.com/uploads/covers/681473bee25e59d34a17668b/39480008-d925-4963-a521-5dea5988e461.png" alt="39480008-d925-4963-a521-5dea5988e461" style="display: block;" width="600" height="400" loading="lazy">

<p><strong>Step #2: Calculate the Predicted Marks</strong></p>
<p>Suppose she wants to calculate the marks scored by a student who studies for 5 hours. This is how she does it:</p>
<pre><code class="language-plaintext">z = w₁x + b₁, = x - 3 = 5 - 3 = 2
h = ReLU(z) = max(0, z) = max(0, 2) = 2
</code></pre>
<p>Finally calculate the predicted marks:</p>
<pre><code class="language-plaintext">ŷ = w₂h + b₂ = 10h + 40 = 10(2) + 40 = 60
</code></pre>
<p>The neural network predicts 60 marks whereas the actual marks in the dataset is 58.</p>
<p><strong>Step #3: Compare Predictions with Actual Marks</strong></p>
<p>After Ms Poly gets all the marks predicted by the neural network, she compares them with the actual data in the table below:</p>
<table>
<thead>
<tr>
<th>Number of Hours Studied</th>
<th>Marks Scored</th>
<th>Predicted Marks</th>
</tr>
</thead>
<tbody><tr>
<td>0</td>
<td>40</td>
<td>40</td>
</tr>
<tr>
<td>1</td>
<td>40</td>
<td>40</td>
</tr>
<tr>
<td>2</td>
<td>41</td>
<td>40</td>
</tr>
<tr>
<td>3</td>
<td>40</td>
<td>40</td>
</tr>
<tr>
<td>4</td>
<td>48</td>
<td>50</td>
</tr>
<tr>
<td>5</td>
<td>58</td>
<td>60</td>
</tr>
<tr>
<td>6</td>
<td>69</td>
<td>70</td>
</tr>
<tr>
<td>7</td>
<td>80</td>
<td>80</td>
</tr>
<tr>
<td>8</td>
<td>80</td>
<td>90</td>
</tr>
</tbody></table>
<img src="https://cdn.hashnode.com/uploads/covers/681473bee25e59d34a17668b/b0210710-a870-4b3d-a829-054d9f091538.png" alt="b0210710-a870-4b3d-a829-054d9f091538" style="display: block;" width="600" height="400" loading="lazy">

<p>The actual and predicted marks don't match exactly, but they're close. The marks keep increasing and don't flatten out in the end because the value keeps increasing after the ReLU threshold.</p>
<p>Through this example Ms Poly has demonstrated how ReLU helps in modeling non-linear relationships in the data.</p>
<h3 id="heading-predicting-passfail-using-relu-and-sigmoid">Predicting Pass/Fail Using ReLU and Sigmoid</h3>
<p>Here Ms Poly will use a neural network to predict whether a student passes or fails in the final exam. She assumes a student needs to score a minimum of 50 marks to pass. This network will be used to predict the probability of passing the exam.</p>
<p><strong>Step #1: Set Up the Network</strong></p>
<p>Ms Poly has the set up the deep neural network with simple equations in the following way:</p>
<ul>
<li><p>Input Layer: The number of hours studied (x) is received here.</p>
</li>
<li><p>Hidden Layer: Linear transformation and ReLU is applied to the input.</p>
<pre><code class="language-plaintext">z₁ = w₁x + b₁, = x - 4      (w₁=1, b₁=-4)
h = ReLU(z₁) = max(0, z₁)
</code></pre>
</li>
<li><p>Output Layer: The pass/fail is predicted after applying sigmoid activation to the linear transformation of the hidden layer's output(h).</p>
<pre><code class="language-plaintext">z₂ = w₂h + b₂ = 2h - 1      (w₂=2, b₂=-1)
p = σ(z₂) = 1 / (1 + exp(-z₂))
ŷ = Pass, if p &gt;= 0.5
ŷ = Fail, if p &lt; 0.5
</code></pre>
</li>
</ul>
<img src="https://cdn.hashnode.com/uploads/covers/681473bee25e59d34a17668b/c4508adf-b2c4-42ae-b297-29afd8ec3409.png" alt="c4508adf-b2c4-42ae-b297-29afd8ec3409" style="display: block;" width="600" height="400" loading="lazy">

<p><strong>Step #2: Calculate the Pass/Fail Prediction</strong></p>
<p>Suppose she wants to predict the result for a student who studies for 3 hours. This is how she does it:</p>
<pre><code class="language-plaintext">z₁ = w₁x + b₁, = x - 4 = 3 - 4 = -1
h = ReLU(z₁) = max(0, z₁) = max(0, -1) = 0
</code></pre>
<p>Predicting if the student passes/fails:</p>
<pre><code class="language-plaintext">z₂ = w₂h + b₂ = 2h - 1 = 2(0) - 1 = -1
p = σ(z₂) = 1 / (1 + exp(-z₂)) = 1 / (1 + exp(-(-1))) ≈ 0.269
</code></pre>
<p>Since 0.269&lt;0.5, the student's result is <strong>Fail</strong>.</p>
<p>Now for the result of a student who studies for 5 hours:</p>
<pre><code class="language-plaintext">z₁ = w₁x + b₁, = x - 4 = 5 - 4 = 1
h = ReLU(z₁) = max(0, z₁) = max(0, 1) = 1
</code></pre>
<p>Predicting if the student passes/fails:</p>
<pre><code class="language-plaintext">z₂ = w₂h + b₂ = 2h - 1 = 2(1) - 1 = 1
p = σ(z₂) = 1 / (1 + exp(-z₂)) = 1 / (1 + exp(-1)) ≈ 0.731
</code></pre>
<p>Since 0.731&gt;0.5, the student's result is <strong>Pass</strong>.</p>
<p><strong>Step #3: Compare Predictions with Actual Results</strong></p>
<table>
<thead>
<tr>
<th>Number of Hours Studied</th>
<th>Marks Scored</th>
<th>Actual Result</th>
<th>Predicted Score</th>
<th>Predicted Result</th>
</tr>
</thead>
<tbody><tr>
<td>0</td>
<td>40</td>
<td>Fail</td>
<td>0.269</td>
<td>Fail</td>
</tr>
<tr>
<td>1</td>
<td>40</td>
<td>Fail</td>
<td>0.269</td>
<td>Fail</td>
</tr>
<tr>
<td>2</td>
<td>41</td>
<td>Fail</td>
<td>0.269</td>
<td>Fail</td>
</tr>
<tr>
<td>3</td>
<td>40</td>
<td>Fail</td>
<td>0.269</td>
<td>Fail</td>
</tr>
<tr>
<td>4</td>
<td>48</td>
<td>Fail</td>
<td>0.269</td>
<td>Fail</td>
</tr>
<tr>
<td>5</td>
<td>58</td>
<td>Pass</td>
<td>0.731</td>
<td>Pass</td>
</tr>
<tr>
<td>6</td>
<td>69</td>
<td>Pass</td>
<td>0.953</td>
<td>Pass</td>
</tr>
<tr>
<td>7</td>
<td>80</td>
<td>Pass</td>
<td>0.993</td>
<td>Pass</td>
</tr>
<tr>
<td>8</td>
<td>80</td>
<td>Pass</td>
<td>0.999</td>
<td>Pass</td>
</tr>
</tbody></table>
<img src="https://cdn.hashnode.com/uploads/covers/681473bee25e59d34a17668b/2bf27e7a-4a54-4671-b853-6bf16b0b0ec0.png" alt="2bf27e7a-4a54-4671-b853-6bf16b0b0ec0" style="display: block;" width="600" height="400" loading="lazy">

<p>The network correctly classifies the result of all the students in this example. As the study hours increase beyond 4, the predicted score increases, making pass prediction more likely.</p>
<p>Through this example Ms Poly has demonstrated how ReLU and sigmoid work together. ReLU transforms the input in the hidden layer and sigmoid helps in converting the output to a score that can be used to make Pass/Fail prediction.</p>
<h2 id="heading-final-thoughts">Final Thoughts</h2>
<p>The simple examples shown above help us understand an important rule about neural networks: the relationship between the outputs and the inputs can behave differently across different parts of the input. They need to be captured in order to produce meaningful results from real-world data.</p>
<p>A straight line equation is enough when the relationship in data is simple and consistent. But real-life data isn't always that straightforward. By introducing non-linearity, neural networks can move beyond straight-line relationships and learn complex relationships hidden in data.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How Neural Networks Work – Explained Using the Straight Line Equation y = ax + b ]]>
                </title>
                <description>
                    <![CDATA[ Did you know that every data scientist who builds a complex neural network starts with a fundamental question, “How does the output change when the input changes?“ A straight line equation y = ax+b answers it in the simplest way possible. y can incre... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/neural-networks-explained-using-y-ax-b/</link>
                <guid isPermaLink="false">695ef4246f1bfe13bf31abe9</guid>
                
                    <category>
                        <![CDATA[ Deep Learning ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Data Science ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Samyukta Hegde ]]>
                </dc:creator>
                <pubDate>Thu, 08 Jan 2026 00:02:44 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/res/hashnode/image/upload/v1767800625537/5bb99a58-d247-4933-b60b-fd2c14651542.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Did you know that every data scientist who builds a complex neural network starts with a fundamental question, “How does the output change when the input changes?“</p>
<p>A straight line equation <code>y = ax+b</code> answers it in the simplest way possible. <code>y</code> can increase, decrease, or stay the same when <code>x</code> changes.</p>
<p>On the other hand, a deep neural network tries to answer it in a flexible way. It’s only possible because of multiple layers of straight line calculations stacked one over another along with non linear adjustments to help the network adapt and produce the desired result.</p>
<p>Since a straight line is the essence of neural networks, I think it’s time we try to understand the subtle details of <code>y = ax+b</code>, which I refer to as the <strong>magical equation</strong>. We’ll also go through the basics of linear regression and classification, which should help you understand the progression of a simple straight line to a complex deep neural network.</p>
<h2 id="heading-table-of-contents">Table of Contents</h2>
<ul>
<li><p><a class="post-section-overview" href="#heading-prerequisites">Prerequisites</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-yaxb">y=ax+b</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-linear-regression">Linear Regression</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-linear-classification">Linear Classification</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-comparison">Comparison</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-key-additions-to-help-build-deep-neural-networks">Key Additions to Help Build Deep Neural Networks</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-modelling-a-deep-neural-network">Modelling a Deep Neural Network</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-final-thoughts">Final Thoughts</a></p>
</li>
</ul>
<h2 id="heading-prerequisites">Prerequisites</h2>
<ul>
<li><p>A basic understanding of linear algebra, particularly <code>y=ax+b</code>.</p>
</li>
<li><p>General idea about linear regression and classification.</p>
</li>
<li><p>Familiarity with the concept of deep neural networks.</p>
</li>
</ul>
<h2 id="heading-yaxb">y=ax+b</h2>
<p>A straight line simply means that output changes steadily as input changes. There are no surprises (that is, no non linearity). Let’s analyze it properly.</p>
<pre><code class="lang-plaintext">y =&gt; Output variable
x =&gt; Input variable
a =&gt; Amount by which y changes when x changes (slope)
b =&gt; Value of y when x is 0 (y intercept)
</code></pre>
<p>We can take an example and model it in the same form to understand it better.</p>
<p>Ms. Poly is a math teacher who wants to formulate a study plan for her students to excel in an upcoming final exam. For simplicity, she creates a rule of thumb using only one factor: the number of hours studied per week. It has a direct impact on the marks scored by a student.</p>
<p>Before beginning, she makes certain assumptions:</p>
<ul>
<li><p>Every student is capable of scoring at least 30 without studying.</p>
</li>
<li><p>For every hour a student studies, an additional 3 marks can be scored.</p>
</li>
</ul>
<p>She then comes up with the following equation based on her ideas: <code>y = 3x+30</code></p>
<pre><code class="lang-plaintext">y =&gt; Marks scored.
x =&gt; Number of hours studied.
a=3 =&gt; Increase in marks for every hour studied
b=30 =&gt; Minimum marks
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1764650083131/997f2a53-78ac-4b6f-a0c1-b995fb515075.png" alt="Plot of y=3x+30" class="image--center mx-auto" width="1920" height="1080" loading="lazy"></p>
<p>In the above graph, she plots the points based on the results of the equation. As expected, it is a straight line. If she needs the marks scored for <code>9</code> hours of study, she can get it by just substituting <code>x=9</code> in <code>y=3x+30</code>. Note that the data (<code>x</code> and <code>y</code>) are just based on her hunch and aren’t real.</p>
<p>But Ms. Poly wants to guide her students on how to prepare for the final exam based on actual data. So she conducts a pop quiz and grades it. In order to formulate a study plan, she interviews her students and collects information on how many hours they study math per week. She creates a table with two columns: number of hours studied (<code>x</code>) per week and marks scored (<code>y</code>). She tries her old formula <code>y=3x+30</code>, but it doesn’t seem to work. Thus, she doesn’t have any sensible equation describing the relation between <code>x</code> and <code>y</code>.</p>
<p>Let’s assume that a new student who hasn’t attended any exam (no <code>y</code> available) joins the class the next day, and Ms. Poly only knows the number of hours dedicated per week (<code>x</code>). How can she answer the question below?</p>
<p><em>If the new student studies for a certain number of hours (</em><code>x</code><em>), what can be the marks scored (</em><code>y</code><em>) in the exam?</em></p>
<p>It’s impossible unless there’s an equation defining the sample data. So, her task is to find one that fits the given points. This process is called curve fitting or regression.</p>
<h2 id="heading-linear-regression">Linear Regression</h2>
<p>The core idea of linear regression to find a straight line that captures the trend of the existing data to facilitate predictions for new input data. Now, let’s dive straight into the example to understand the concept better.</p>
<p>Ms. Poly is determined to arrive at a solution. She plots the collected data on a graph to get a better picture.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1764651274954/0aa2dfc2-d846-40e6-872d-e7d5abe598a8.png" alt="Input Data" class="image--center mx-auto" width="1920" height="1080" loading="lazy"></p>
<p>She has absolutely no idea how <code>x</code> and <code>y</code> are related. So, she must figure out a formula, by trial and error, that roughly fits the points. She has to start with an intuitive guess, try to improve it in the subsequent steps and then arrive at the best possible solution.</p>
<p><strong>Trial 1</strong>: Ms. Poly begins with her previous straight line equation.</p>
<p><code>y = 3x+30</code></p>
<p>She substitutes different values of <code>x</code> and plots it alongside the collected input data. This way she can get a clear picture of the differences in her assumption and reality.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1764651323645/a3e79765-99bc-42be-8836-82119d7fbf66.png" alt="Linear Regression-Trial 1" class="image--center mx-auto" width="1920" height="1080" loading="lazy"></p>
<p><strong>Trial 2</strong>: She observes that the line needs a little more slope. This simply means that, in reality, more marks are being scored for every additional hour of study. By changing it from <code>3</code> to <code>4</code>, the equation becomes:</p>
<p><code>y = 4x+30</code></p>
<p>The following graph depicts the new line alongside the sample data:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1764651379913/42a8fc61-7927-46de-aadf-b691544b9a1b.png" alt="Linear Regression-Trial 2" class="image--center mx-auto" width="1920" height="1080" loading="lazy"></p>
<p><strong>Trial 3:</strong> It looks better but she feels there is a need to shift the whole line upwards. This means that higher marks are being scored even if a student doesn’t dedicate any time for math in a week. She decides to retain the previous slope but changes the starting marks by <code>10</code>, thus arriving at:</p>
<p><code>y = 4x+40</code></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1764651454435/5fea2d39-8254-48e6-be14-69c803982ec7.png" alt="Linear Regression-Trial 3" class="image--center mx-auto" width="1920" height="1080" loading="lazy"></p>
<p>This particular line covers most of the points and can be considered the best possible solution.</p>
<p>Now, if she wishes to ascertain the marks scored by the new student who studied for <code>3.5</code> hours, she pins the value inside the formula and calculates the answer: <code>y = 4*(3.5)+40=54</code></p>
<p>We saw how Ms. Poly arrived at a straight line equation to predict the output for an unknown input. Now she can chalk out a study plan for her class based on the equation.</p>
<p>Here, an expression is formulated to ascertain the change in output when the input changes. It looks like Ms. Poly is thinking like a data scientist. She has in fact modelled a very simple neural network for regression. The equation <code>y=4x+40</code> can be considered as the only neuron (processing unit) within it. She’s adjusted the parameters <code>a</code> (weight) and <code>b</code> (bias) to arrive at the final formula which covers most of the points (thus minimizing the loss).</p>
<p>Here’s a breakdown of the <code>y = 4x+40</code> equation:</p>
<pre><code class="lang-plaintext">y =&gt; Marks scored.
x =&gt; Number of hours studied.
a=4 =&gt; Increase in marks for every hour studied
b=40 =&gt; Minimum marks
</code></pre>
<p>At present, it is a rudimentary neural network which has no layering and non-linearity.</p>
<p>Now let’s shift our attention to a completely different scenario. Ms. Poly, being a teacher, wants to ensure that all her students pass the exam. Assuming, as an end result, she’s not interested in predicting the marks scored. She just wants to know:</p>
<p><em>If a student studies for a certain number of hours (</em><code>x</code><em>), will the student pass/fail(y) the exam?</em></p>
<p>This leads her to the process of classification.</p>
<h2 id="heading-linear-classification">Linear Classification</h2>
<p>The linear classification process uses a simple straight line to divide the data into categories or classes. The line acts as a boundary so that the classes fall on either side of it. First, Ms. Poly defines the boundary condition for pass and fail.</p>
<p><em>If marks scored&gt;=50, pass</em></p>
<p><em>If marks scored&lt;50, fail</em></p>
<p>According to the data table, <code>x=3</code> corresponds to <code>y=52</code> (boundary condition). Therefore she considers <code>x=3</code> as the classification line***.***</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1764651531018/e669ed7b-1c86-4093-b7e5-feb06464ebfe.png" alt="Linear Classification" class="image--center mx-auto" width="1920" height="1080" loading="lazy"></p>
<p><code>x=3</code> seems to segregate the points into the categories properly. She tries to confirm it by substituting another value. Thus, if a student studied for <code>9</code> hours, the score would lie towards the right side of <code>x=3</code>. So, they’d pass as per the classification equation.</p>
<p>Again, she’s arrived at an expression to ascertain the change in output when the input changes. But here, she has modelled a basic neural network for classification. The equation x=3 is the only neuron within it. It can be considered to be having two parts as explained below.</p>
<ol>
<li><p><strong>Pre-Activation Part:</strong> This portion of the neuron computes an intermediate value which is helpful in further processing. She’s figured out the parameters <code>a</code> (weight) and <code>b</code> (bias) to arrive at the following formula: <code>z = x-3</code></p>
<pre><code class="lang-plaintext"> z =&gt; Intermediate Value.
 x =&gt; Number of hours studied.
 a=1 =&gt; Influence of the number of hours studied on the marks scored
 b=-3 =&gt; Minimum number of hours to study to pass the exam = 3
</code></pre>
</li>
<li><p><strong>Activation Part:</strong> This portion triggers the neuron to make decisions based on a threshold value. The following equation segregates the points into two classes.</p>
<pre><code class="lang-plaintext"> y = 1 (Pass) if z&gt;=0
 y = 0 (Fail) if z&lt;0
</code></pre>
</li>
</ol>
<p>This is a very plain neural network which has no layering and non-linearity but has pre-activation and activation parts inside a neuron.</p>
<h2 id="heading-comparison">Comparison</h2>
<p>We looked at the examples of both linear regression and classification used by Ms. Poly. <strong>Regression</strong> helps in predicting a value while <strong>Classification</strong> helps in decision making. Let’s draw a small table to summarize the differences.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1764652317811/f4411011-fcd3-4a53-b116-a3c8a27c81d8.png" alt="Comparison between Linear Regression and Classification" class="image--center mx-auto" width="1565" height="756" loading="lazy"></p>
<p>Upon careful observation we notice that both answer the question of how input change affects output.</p>
<p>But at a slightly higher level of complexity than a straight line. Because in the case of both regression and classification, we try to figure out the equation parameters by trial and error.</p>
<p>Here, since the requirements are simple, Ms. Poly just uses a straight line to solve both. A simple linear equation can handle only one steady trend. But in real life, problems that need solving are far more challenging and unpredictable. Some examples are:</p>
<p><strong>Image Classification</strong>: An output label is produced based on the input images.</p>
<p><strong>Text Translation</strong>: An English sentence can be given as an input to be translated to say, Spanish.</p>
<p><strong>Chatbots</strong>: A text prompt is typed in by a user and a meaningful and relevant output is generated.</p>
<p>She probably should have to use a deep neural network if both data and task were complex. That presents another question: <strong>How does one build a deep neural network?</strong></p>
<p>We will explore it further by extending the same example to a more realistic version.</p>
<h2 id="heading-key-additions-to-help-build-deep-neural-networks">Key Additions to Help Build Deep Neural Networks</h2>
<p>In the above sections, we noted that Ms. Poly was interested in predicting the exam results of a student using just one factor - number of hours studied. However, in practice, is that one factor sufficient in determining the marks scored or whether the student passes the exam?</p>
<p>No. It’s not enough. She needs to take into account a lot of aspects like:</p>
<ul>
<li><p>Number of hours studied</p>
</li>
<li><p>Number of hours of sleep/rest</p>
</li>
<li><p>Burnout due to over-studying</p>
</li>
<li><p>Difficulty level of topics in math</p>
</li>
<li><p>Pattern of the exam, and so on.</p>
</li>
</ul>
<p>All the above neither act independently nor do they have a simple linear relation with the marks scored. So, she has to solve this problem by stacking the contributing factors one above the other in layers and also adding the element of non linearity. Let’s take a look at each in detail.</p>
<h3 id="heading-layering">Layering</h3>
<p>Burnout leads to lower score whereas good sleep increases score. But burnout can be reduced if the student is well rested. So, the impact on the final score when these two factors interact should be taken into account. This is possible only when the system solves it in layers. The first layer can deal with how they independently influence the score, the next layer can explore the interaction between them.</p>
<h3 id="heading-non-linearity">Non-Linearity</h3>
<p>If the number of hours studied increases, the score might increase but when burnout overpowers the effect of study hours, the score reduces. The combined effect results in a non-linear graph. There is a rise and then dip in the score based on number of hours studied. It’s evident that the relationship is not straightforward as in a straight line. That’s where it becomes necessary to add non-linearity in the calculations. It helps the system to respond differently according to the conditions, allowing for flexibility in dealing with real world data and conditions.</p>
<p>Thus, Ms. Poly would have to extend the idea of linear regression/classification by including layering and non-linearity to build a fully functional neural network to help build a practical study plan.</p>
<h2 id="heading-modelling-a-deep-neural-network">Modelling a Deep Neural Network</h2>
<p>Ms. Poly should start the work on modelling a deep neural network by following the steps mentioned below:</p>
<h3 id="heading-step-1-define-the-problem-clearly"><strong>Step #1 - Define the Problem Clearly</strong></h3>
<p>The following factors should be considered before she begins the process of modelling:</p>
<ul>
<li><p>What are the input features?</p>
</li>
<li><p>What are the output features?</p>
</li>
<li><p>What type of problem is it (regression/classification)?</p>
</li>
</ul>
<h3 id="heading-step-2-define-the-input-layer"><strong>Step #2 - Define the Input Layer</strong></h3>
<p>The input features form the first layer. There is no computation in this stage. They are represented as:</p>
<pre><code class="lang-plaintext">x1: Number of hours studied
x2: Number of hours of sleep/rest
x3: Burnout due to over-studying
x4: Difficulty level of topics in Maths
x5: Pattern of the exam
</code></pre>
<h3 id="heading-step-3-define-the-first-hidden-layer"><strong>Step #3 - Define the First Hidden Layer</strong></h3>
<p>This step consists of two parts:</p>
<p><strong>Apply Linear Transformation</strong>: The actual learning begins here. A straight line equation is used to understand the combined effect of the inputs. The general formula is <code>z=Wx+b</code>.</p>
<pre><code class="lang-plaintext">z: Intermediate value or Pre-activation
W: Weight matrix which consists of values corresponding to the impact of
each input feature
x: Matrix consisting of input features, [x1, x2, x3, x4, x5]
b: Bias which represents the initial assumptions of the teacher(when x=0)
</code></pre>
<p>It looks similar to a linear regression/classification equation. At first <code>W</code> and <code>b</code> are initialized to random values. Then in the subsequent steps, they are adjusted like it was done in earlier examples. We can consider the following combinations assuming we have two neurons in this layer:</p>
<p><strong>Neuron 1:</strong> It can focus on study hours, burnout, and rest, with other features contributing less significantly.</p>
<p><strong>Neuron 2</strong>: It can emphasize more on the difficulty level of the topic and the exam type compared to other inputs.</p>
<p>It’s important to note that this layer doesn’t calculate the interactions between the features but only on the way different linear combinations work together but independently. To make it clearer, how they contribute independently are added together. We don’t know how one input feature influences the other. For example, we know sleep increases score and burnout reduces score, but what we don’t know at this stage is if sleep reduces burnout, which in turn can influence the final score.</p>
<p><strong>Add Non-Linearity</strong>: This step, also called activation, helps in capturing the complexities in different combinations of the features. Less study results in low marks, and too much burnout also results in low marks. It means there is a curve in the score graph which can’t be represented by a linear equation. The activation function is applied to the intermediate value and can be expressed as:</p>
<p><strong>a = g(z)</strong></p>
<pre><code class="lang-plaintext">a: Activation output
g: Activation function
z: Intermediate value or Pre-activation
</code></pre>
<p>For example: <code>ReLU</code> is an activation function which outputs <code>z</code> only if <code>z</code> is positive, else <code>0</code>.</p>
<p><strong>y = ReLU(z)=max(0,z)</strong></p>
<p>We can see that it has no steady slope and is a non-linear activation function. It can suit this scenario as it lets the value pass through to the next layer only if the combined effect of features is greater than 0. Neuron 1 will let it’s output go to the next layer only if the intermediate value (<code>z</code>) that results from study hours, burnout and rest, is large enough to be influencing the final decision, else it’s ignored. There are multiple options for non-linear activation functions that one can choose from.</p>
<h3 id="heading-step-4-stack-layers-one-above-the-other"><strong>Step #4 - Stack Layers One Above the Other</strong></h3>
<p>This step helps in learning the mutual interactions between the inferences learned from the first hidden layer. The network attempts to understand the intricate details of the influencing factors and build a stable system. It is here that details of whether sleep reduces burnout are figured out. Every layer consists of linear and non linear transformations applied on the input, which are values obtained from the previous layer. Likewise multiple layers can be stacked one over the other based on the requirements. In this example, for representation, we have taken two hidden layers with two neurons each. The number of layers and neurons can vary based on requirements.</p>
<h3 id="heading-step-5-define-the-output-features"><strong>Step #5 - Define the Output Feature(s)</strong></h3>
<p>This appears to be the final stage in a deep neural network. Ms. Poly can decide what she wants for output: predict the marks scored by a student or predict if the student passes/fails the exam. If she wants the final marks scored, she just has to apply linear transformation in the neuron in the final layer to produce the output. If she wants pass/fail status, she has to apply both linear and non-linear transformations to achieve the desired results.</p>
<p>The diagram below shows an abstract representation of the deep neural network.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1766153114888/1e513840-483a-43cf-b062-ce5af886a04e.png" alt="Abstract Representation of a Deep Neural Network" class="image--center mx-auto" width="1024" height="768" loading="lazy"></p>
<p>The next steps are:</p>
<p><strong>Training the model</strong>: The network is trained in the following way:</p>
<ul>
<li><p>Random weights and biases are assigned to the linear transformation portions of the network.</p>
</li>
<li><p>Then the network makes a prediction which is compared with the expected result.</p>
</li>
<li><p>If there are gaps between the actual result and the predicted result, corrections are made in weights and biases (this step is similar to what was done in linear regression and classification).</p>
</li>
<li><p>The steps above are repeated until the results improve.</p>
</li>
</ul>
<p><strong>Using the model</strong>: After the model has been trained, it is capable of yielding results for new input values.</p>
<h2 id="heading-final-thoughts"><strong>Final Thoughts</strong></h2>
<p>In this article, we began with the basics of a straight line equation. Then we gradually navigated through slightly more elaborate concepts like linear regression and classification. They laid the groundwork for delving into the seemingly mysterious deep neural networks. But they are in fact built by stacking layers of linear transformations and non-linear activations, which help understand sophisticated real world patterns.</p>
<p>Despite all the complexities and layers, we can see that the straight line remains the foundation upon which neural networks are built. As we saw earlier, the equation that a deep neural network begins with is our <em>magical equation:</em> <code>y = ax+b</code>.</p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
