<?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 ARYA PRATAMA on Medium]]></title>
        <description><![CDATA[Stories by ARYA PRATAMA on Medium]]></description>
        <link>https://medium.com/@rhamabiasa?source=rss-3b31634157d3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*LRqsEatv0L-ihKsKVLRj9Q.jpeg</url>
            <title>Stories by ARYA PRATAMA on Medium</title>
            <link>https://medium.com/@rhamabiasa?source=rss-3b31634157d3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 20:34:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rhamabiasa/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[Can we create a neural network from only numpy?]]></title>
            <link>https://medium.com/@rhamabiasa/can-we-create-a-neural-network-from-only-numpy-a1ec0adac7d2?source=rss-3b31634157d3------2</link>
            <guid isPermaLink="false">https://medium.com/p/a1ec0adac7d2</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[ARYA PRATAMA]]></dc:creator>
            <pubDate>Sun, 04 Jan 2026 06:17:49 GMT</pubDate>
            <atom:updated>2026-01-04T06:17:49.733Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*55M2w3rP9Etomgku.jpg" /><figcaption>source: 3Blue1Brown</figcaption></figure><p>Of course you can. In this article, we will simulate how Neural network can classify input.</p><p>this is my repository: <a href="https://github.com/Turusore08/Neural-Network-with-only-numpy">https://github.com/Turusore08/Neural-Network-with-only-numpy</a></p><p>Lets begin</p><h3>Introduction: The Feynman Principle</h3><p>Richard Feynman famously wrote on his blackboard: <em>“What I cannot create, I do not understand.”</em></p><p>Modern Deep Learning frameworks like PyTorch and TensorFlow have democratized AI, but they have also created a generation of “import-engineers” who treat Neural Networks as black boxes. They know <em>how</em> to stack layers, but they do not understand <em>why</em> the network learns.</p><p>To truly master Deep Learning, you must strip away the frameworks and implement the mathematics yourself. In this article, we build a 2-layer Neural Network to solve the classic MNIST digit classification problem using nothing but Python’s numpy.</p><p>We will confront the matrix calculus behind <strong>Forward Propagation</strong>, <strong>Softmax</strong>, and the derivation of gradients for <strong>Backpropagation</strong>.</p><h3>Dataset</h3><p>from: <a href="https://www.kaggle.com/competitions/digit-recognizer/data">https://www.kaggle.com/competitions/digit-recognizer/data</a></p><p>We are working with the Kaggle Digit Recognizer dataset. Unlike standard image files (JPG/PNG), this data is flattened.</p><ul><li><strong>Structure:</strong> The training set is a CSV with 785 columns.</li><li><strong>Label:</strong> Column 0 is the ground truth digit ($0–9$).</li><li><strong>Features:</strong> Columns 1–784 represent the pixel intensity ($0–255$).</li><li><strong>Mapping:</strong> The 784 pixels map to a $28 \times 28$ matrix. $pixel_x$ corresponds to row $i$ and column $j$ where $x = i \times 28 + j$.</li></ul><p>This means our Input Layer must have exactly <strong>784 neurons</strong>. Because the input data is row-based (samples as rows) but standard linear algebra notation A = WX + b expects samples as columns, our first step in preprocessing is a <strong>Transpose</strong> operation.</p><h3>The Architecture</h3><p>We are building a standard Multi-Layer Perceptron (MLP).</p><ul><li><strong>Input Layer A[0]:</strong> 784 units (corresponding to 28x28 pixel images).</li><li><strong>Hidden Layer A[1]:</strong> 10 neurons with <strong>ReLU</strong> activation.</li><li><strong>Output Layer A[2]:</strong> 10 neurons with <strong>Softmax</strong> activation (representing probabilities for digits 0–9).</li></ul><h3>Data Shape Orientation</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/918/1*e4OEb6BrTHYv_Jj89YT-CQ.png" /></figure><p>In the code, this requires transposing the raw pandas DataFrame:</p><pre>data = pd.read_csv(&#39;data/train.csv&#39;)<br>data_train = data[1000:m].T<br>Y_train = data_train[0]<br>X_train = data_train[1:n] / 255.  # Normalize pixel values. so from (0-255) to (0-1). This will simplify the calculation</pre><h3>Initialization: Breaking Symmetry</h3><p>we will create class name NeuralNetwork.</p><p>We cannot initialize weights to zero. If we do, every neuron in the hidden layer will compute the exact same gradient and update identically. The network would never learn complex features.</p><p>We use random initialization to break this symmetry. <em>(Note: While He-Initialization is standard for ReLU, here we use a uniform distribution centered at 0 for simplicity, subtracting 0.5 to shift the range).</em></p><pre>class NeuralNetwork:<br>    def __init__(self):<br>        self.W1 = np.random.rand(10, 784) - 0.5<br>        self.b1 = np.random.rand(10, 1) - 0.5<br>        self.W2 = np.random.rand(10, 10) - 0.5<br>        self.b2 = np.random.rand(10, 1) - 0.5</pre><h3>Forward Propagation</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/941/1*QJrezyf5czeri3bxrHck2w.png" /></figure><p>formula softmax:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/731/1*1J2lzly1zTNpeUFPS7qIIQ.png" /></figure><p>the code:</p><pre>def ReLU(self, Z):<br>        return np.maximum(0, Z)<br><br>def softmax(self, Z):<br>        exp_Z = np.exp(Z - np.max(Z, axis=0, keepdims=True)) <br>        return exp_Z / np.sum(exp_Z, axis=0, keepdims=True)<br><br>def forward(self, X):<br>        Z1 = self.W1.dot(X) + self.b1<br>        A1 = self.ReLU(Z1)<br>        Z2 = self.W2.dot(A1) + self.b2<br>        A2 = self.softmax(Z2)<br>        return Z1, A1, Z2, A2</pre><h3>The Loss Function &amp; Backpropagation</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*yqkOkvyiDpHktSY-dgm6hA.png" /></figure><p>The implementation:</p><pre>def one_hot(self, Y):<br>        one_hot_Y = np.zeros((Y.max() + 1, Y.size))<br>        one_hot_Y[Y, np.arange(Y.size)] = 1<br>        return one_hot_Y<br><br>def deriv_relu(self, Z):<br>        return Z &gt; 0<br><br>def backpro(self, Z1, A1, Z2, A2, Y, X):<br>        m = Y.size<br>        one_hot_Y = self.one_hot(Y)<br>        dZ2 = A2 - one_hot_Y<br>        dW2 = (1 / m) * dZ2.dot(A1.T)<br>        db2 = (1 / m) * np.sum(dZ2, axis=1, keepdims=True)<br>        <br>        dZ1 = self.W2.T.dot(dZ2) * self.deriv_relu(Z1)<br>        dW1 = (1 / m) * dZ1.dot(X.T)<br>        db1 = (1 / m) * np.sum(dZ1, axis=1, keepdims=True)<br><br>        return dW1, db1, dW2, db2<br><br>def update_params(self, dW1, db1, dW2, db2, alpha):<br>        self.W1 = self.W1 - alpha * dW1<br>        self.b1 = self.b1 - alpha * db1<br>        self.W2 = self.W2 - alpha * dW2<br>        self.b2 = self.b2 - alpha * db2</pre><h3>Result</h3><pre>def get_prediction(A2):<br>    return np.argmax(A2,0)<br><br>def get_accuration(prediction,Y):<br>    print(&quot;prediction:&quot;, prediction, &quot;actual:&quot;, Y)<br>    return np.sum(prediction ==Y)/ Y.size<br><br>def gradient_descend(X,Y,iterations, alpha):<br>    model = NeuralNetwork()<br>    for i in range(iterations):<br>        Z1,A1,Z2,A2 = model.forward(X)<br>        dW1,db1,dW2,db2 = model.backpro(Z1,A1,Z2,A2,Y,X)<br>        model.update_params(dW1,db1,dW2,db2,alpha)<br>        if i%50 ==0:<br>            print(&quot;iteration:&quot;, i)<br>            print(&quot;accuration:&quot;, get_accuration(get_prediction(A2),Y))<br><br>    return model.W1,model.b1,model.W2,model.b2<br></pre><p>Training on the MNIST dataset using full-batch Gradient Descent yields a rapid increase in accuracy.</p><ul><li><strong>Iteration 0:</strong> ~10% accuracy (random guessing).</li><li><strong>Iteration 450:</strong> ~80% accuracy.</li></ul><p>This demonstrates that the network is effectively learning the spatial hierarchies of the digits.</p><h3>Conclusion</h3><p>Building a Neural Network in NumPy forces you to confront matrix dimensions, broadcasting rules, and the raw calculus of gradient descent. It removes the magic. When you understand that “learning” is simply minimizing a loss function via the chain rule, you stop being a technician and start becoming an engineer.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a1ec0adac7d2" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>