{"id":13936853,"url":"https://github.com/kdexd/digit-classifier","last_synced_at":"2025-07-19T22:32:40.904Z","repository":{"id":92766215,"uuid":"44663424","full_name":"kdexd/digit-classifier","owner":"kdexd","description":"A single handwritten digit classifier, using the MNIST dataset. Pure Numpy. ","archived":true,"fork":false,"pushed_at":"2019-10-12T20:52:40.000Z","size":36462,"stargazers_count":786,"open_issues_count":0,"forks_count":87,"subscribers_count":23,"default_branch":"master","last_synced_at":"2024-08-08T23:24:34.246Z","etag":null,"topics":["beginner-friendly","deep-learning","neural-network"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kdexd.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-10-21T08:40:38.000Z","updated_at":"2024-07-14T04:32:58.000Z","dependencies_parsed_at":"2023-04-19T21:31:57.110Z","dependency_job_id":null,"html_url":"https://github.com/kdexd/digit-classifier","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kdexd%2Fdigit-classifier","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kdexd%2Fdigit-classifier/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kdexd%2Fdigit-classifier/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kdexd%2Fdigit-classifier/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kdexd","download_url":"https://codeload.github.com/kdexd/digit-classifier/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226693902,"owners_count":17667757,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["beginner-friendly","deep-learning","neural-network"],"created_at":"2024-08-07T23:03:03.497Z","updated_at":"2024-11-27T05:30:36.575Z","avatar_url":"https://github.com/kdexd.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"MNIST Handwritten Digit Classifier\n==================================\n\nAn implementation of multilayer neural network using `numpy` library. The implementation \nis a modified version of Michael Nielsen's implementation in \n[Neural Networks and Deep Learning](http://neuralnetworksanddeeplearning.com/) book. \n\n\n### Brief Background:\n\nIf you are familiar with basics of Neural Networks, feel free to skip this section. For \ntotal beginners who landed up here before reading anything about Neural Networks:\n\n![Sigmoid Neuron](http://i.imgur.com/dOkT9Y9.png)\n\n* Neural networks are made up of building blocks known as **Sigmoid Neurons**. These are \nnamed so because their output follows [Sigmoid Function](https://en.wikipedia.org/wiki/Sigmoid_function).\n* **x\u003csub\u003ej\u003c/sub\u003e** are inputs, which are weighted by **w\u003csub\u003ej\u003c/sub\u003e** weights and the \nneuron has its intrinsic bias **b**. The output of neuron is known as \"activation ( **a** )\".\n\n_**Note:** There are other functions in use other than sigmoid, but this information for\nnow is sufficient for beginners._\n\n* A neural network is made up by stacking layers of neurons, and is defined by the weights \nof connections and biases of neurons. Activations are a result dependent on a certain input.\n\n\n### Why a modified implementation ?\n\nThis book and Stanford's Machine Learning Course by Prof. Andrew Ng are recommended as \ngood resources for beginners. At times, it got confusing to me while referring both resources:\n\nMATLAB has _1-indexed_ data structures, while `numpy` has them _0-indexed_. Some parameters \nof a neural network are not defined for the input layer, so there was a little mess up in \nmathematical equations of book, and indices in code. For example according to the book, the \nbias vector of second layer of neural network was referred as `bias[0]` as input layer (first \nlayer) has no bias vector. I found it a bit inconvenient to play with.\n\nI am fond of Scikit Learn's API style, hence my class has a similar structure of code. While \ntheoretically it resembles the book and Stanford's course, you can find simple methods such \nas `fit`, `predict`, `validate` to train, test, validate the model respectively.\n\n\n### Naming and Indexing Convention:\n\nI have followed a particular convention in indexing quantities.\nDimensions of quantities are listed according to this figure.\n\n![Small Labelled Neural Network](http://i.imgur.com/HdfentB.png)\n\n\n#### **Layers**\n* Input layer is the **0\u003csup\u003eth\u003c/sup\u003e** layer, and output layer \nis the **L\u003csup\u003eth\u003c/sup\u003e** layer. Number of layers: **N\u003csub\u003eL\u003c/sub\u003e = L + 1**.\n```\nsizes = [2, 3, 1]\n```\n\n#### **Weights**\n* Weights in this neural network implementation are a list of \nmatrices (`numpy.ndarrays`). `weights[l]` is a matrix of weights entering the \n**l\u003csup\u003eth\u003c/sup\u003e** layer of the network (Denoted as **w\u003csup\u003el\u003c/sup\u003e**).  \n* An element of this matrix is denoted as **w\u003csup\u003el\u003c/sup\u003e\u003csub\u003ejk\u003c/sub\u003e**. It is a \npart of **j\u003csup\u003eth\u003c/sup\u003e** row, which is a collection of all weights entering \n**j\u003csup\u003eth\u003c/sup\u003e** neuron, from all neurons (0 to k) of **(l-1)\u003csup\u003eth\u003c/sup\u003e** layer.  \n* No weights enter the input layer, hence `weights[0]` is redundant, and further it \nfollows as `weights[1]` being the collection of weights entering layer 1 and so on.\n```\nweights = |¯   [[]],    [[a, b],    [[p],   ¯|\n          |              [c, d],     [q],    |\n          |_             [e, f]],    [r]]   _|\n```\n\n#### **Biases**\n* Biases in this neural network implementation are a list of one-dimensional \nvectors (`numpy.ndarrays`). `biases[l]` is a vector of biases of neurons in the \n**l\u003csup\u003eth\u003c/sup\u003e** layer of network (Denoted as **b\u003csup\u003el\u003c/sup\u003e**).  \n* An element of this vector is denoted as **b\u003csup\u003el\u003c/sup\u003e\u003csub\u003ej\u003c/sub\u003e**. It is a \npart of **j\u003csup\u003eth\u003c/sup\u003e** row, the bias of **j\u003csup\u003eth\u003c/sup\u003e** in layer.  \n* Input layer has no biases, hence `biases[0]` is redundant, and further it \nfollows as `biases[1]` being the biases of neurons of layer 1 and so on.\n```\nbiases = |¯   [[],    [[0],    [[0]]   ¯|\n         |     []],    [1],             |\n         |_            [2]],           _|\n```\n\n#### **'Z's**\n* For input vector **x** to a layer **l**, **z** is defined as: \n**z\u003csup\u003el\u003c/sup\u003e = w\u003csup\u003el\u003c/sup\u003e . x + b\u003csup\u003el\u003c/sup\u003e**\n* Input layer provides **x** vector as input to layer 1, and itself has no input, \nweight or bias, hence `zs[0]` is redundant.\n* Dimensions of `zs` will be same as `biases`.\n\n#### **Activations**\n* Activations of **l\u003csup\u003eth\u003c/sup\u003e** layer are outputs from neurons of **l\u003csup\u003eth\u003c/sup\u003e** \nwhich serve as input to **(l+1)\u003csup\u003eth\u003c/sup\u003e** layer. The dimensions of `biases`, `zs` and \n`activations` are similar.\n* Input layer provides **x** vector as input to layer 1, hence `activations[0]` can be related \nto **x** - the input training example.\n\n#### **Execution of Neural network**\n```\n#to train and test the neural network algorithm, please use the following command\npython main.py\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkdexd%2Fdigit-classifier","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkdexd%2Fdigit-classifier","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkdexd%2Fdigit-classifier/lists"}