{"id":20580994,"url":"https://github.com/nikhilroxtomar/fully-connected-neural-network-in-numpy","last_synced_at":"2026-04-22T13:31:09.150Z","repository":{"id":91224750,"uuid":"141387843","full_name":"nikhilroxtomar/Fully-Connected-Neural-Network-in-NumPy","owner":"nikhilroxtomar","description":"This is an efficient implementation of a fully connected neural network in NumPy.","archived":false,"fork":false,"pushed_at":"2020-05-22T15:28:29.000Z","size":45,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-06T12:15:54.267Z","etag":null,"topics":["dnn","neural-network","numpy","python3"],"latest_commit_sha":null,"homepage":"https://idiotdeveloper.com","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/nikhilroxtomar.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":"2018-07-18T06:00:14.000Z","updated_at":"2021-03-16T02:25:59.000Z","dependencies_parsed_at":"2023-03-20T18:16:54.604Z","dependency_job_id":null,"html_url":"https://github.com/nikhilroxtomar/Fully-Connected-Neural-Network-in-NumPy","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/nikhilroxtomar/Fully-Connected-Neural-Network-in-NumPy","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikhilroxtomar%2FFully-Connected-Neural-Network-in-NumPy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikhilroxtomar%2FFully-Connected-Neural-Network-in-NumPy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikhilroxtomar%2FFully-Connected-Neural-Network-in-NumPy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikhilroxtomar%2FFully-Connected-Neural-Network-in-NumPy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nikhilroxtomar","download_url":"https://codeload.github.com/nikhilroxtomar/Fully-Connected-Neural-Network-in-NumPy/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikhilroxtomar%2FFully-Connected-Neural-Network-in-NumPy/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32139064,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-22T13:27:12.868Z","status":"ssl_error","status_checked_at":"2026-04-22T13:26:44.791Z","response_time":58,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["dnn","neural-network","numpy","python3"],"created_at":"2024-11-16T06:26:23.611Z","updated_at":"2026-04-22T13:31:09.134Z","avatar_url":"https://github.com/nikhilroxtomar.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Fully Connected Neural Network in NumPy\r\n\r\nIt is a simple fully connected neural network that is build from scratch using NumPy and Python3. I developed this project as a self interest to learn the working of a neural network, to understand the backend of a neural network.\r\n\r\n## Getting Started\r\n\r\nJust simply download this code and first run the iris.py file. The iris.py has the neural network that is trained on IRIS Datatset.\r\nIt will help you to build your own neural network.\r\n\r\n### Prerequisites\r\n\r\nYou only need **numpy** installed on your python3 environment.\r\n\u003e sudo pip3 install numpy\r\n\r\n### Example\r\n\r\nFirst import the DNN class from the dnn directory and dnn.py file\r\n```\r\nfrom dnn.dnn import DNN\r\n```\r\n\r\nCreate an object of the class\r\n```\r\ninput_shape = (4, 2)\r\nnn = DNN(shape=input_shape)\r\n```\r\n\r\nThe input shape it the shape of the input of your training dataset.\r\nExample: (4, 2)\r\n4: The number of exmaples in the dataset, you can vary this during initialize, it does have any effect.\r\n2: The size of the input data, this is really very important.\r\n\r\nNow add layers to it\r\n```\r\nnn.add(5, activation='tanh')\r\nnn.add(1, activation='sigmoid')\r\n```\r\n\r\nCurrently this project supports only **sigmoid** and **tanh** activation function. Sigmoid is the default activation function.\r\n\r\nNow compile your neural network\r\n\r\n```\r\nnn.compile(epochs=1000, display_step=100, batch_size=64, lr=0.05, validation_split=0.2, metrics='accuracy')\r\n```\r\n\r\nThe compile function is used to give all the necessary information to the neural network. It is a compulsoty function, you need to call \r\nit before working on training.\r\n\r\n* **epochs**: training iterations\r\n* **display_step**: the iteration interval at which the training information should be displayed\r\n* **batch_size**: the batch of the data you want to give to the network during training\r\n* **lr**: the learning rate\r\n* **validation_split**: it split the dataset into the validation dataset and the training dataset\r\n* **metrics**: currently it only support **accuracy**, you specify it, then it will provide you with the accuracy of the training \r\n    data during the training\r\n    \r\n```\r\nnn.load_model(path='dataset/iris')\r\n```\r\n\r\n**nn.load_model(path=None)** - This function is used for loading the saved model.\r\n\r\nOnce your have a save model file then you need not to specify the layers and need not to call the compile()\r\nfunction.\r\n\r\nThe saved model have all the data regarding your network, including your layers, weights, activation functions,\r\nthe input_shape, all the value you give in the compile function.\r\n\r\nif you want to train you model then you can call the compile function overwrite all those value that the\r\nsaved model have specified.\r\n\r\nYou cannot change the weights, activation function, layers, i.e., you cannot change anything regarding the\r\nlayers of your network.\r\n\r\n```\r\nnn.train(train_X, train_Y)\r\n```\r\n\r\n**nn.train(X, Y)** - This function is used to train the model.\r\nYou need to provide current format data to the network as no preprocessing of data will be done y the network\r\n\r\n```\r\nnn.save_model(path='dataset/iris')\r\n```\r\nSaving the model\r\n\r\n```\r\nprint(nn.evaluate(train_X, train_Y))\r\n```\r\nEvaluating the model, it returns the accuracy that the model has achieved\r\n\r\n### Complete Code\r\n```\r\nimport numpy as np\r\nfrom dnn.dnn import DNN\r\n\r\n## Converting label name to onehot encoding\r\ndef label_encode(label):\r\n\tval=[]\r\n\tif label == \"Iris-setosa\":\r\n\t\tval = [1,0,0]\r\n\telif label == \"Iris-versicolor\":\r\n\t\tval = [0,1,0]\r\n\telif label == \"Iris-virginica\":\r\n\t\tval = [0,0,1]\r\n\treturn val\r\n\r\n## Converting data from the file to the appropriate format\r\ndef data_encode(file):\r\n\tX = []\r\n\tY = []\r\n\ttrain_file = open(file, 'r')\r\n\tfor line in train_file.read().strip().split('\\n'):\r\n\t\tline = line.split(',')\r\n\t\tX.append([line[0], line[1], line[2], line[3]])\r\n\t\tY.append(label_encode(line[4]))\r\n\treturn np.array(X, dtype=np.float64), np.array(Y, dtype=np.float64)\r\n\r\n#Training Dataset\r\ntrain_X , train_Y = data_encode('dataset/iris.train')\r\n\r\ninput_shape = train_X.shape\r\noutput_shape = train_Y.shape[-1]\r\n\r\n## Initializing the DNN Class\r\nnn = DNN(shape=input_shape)\r\n\r\nnn.add(8, activation='tanh')\r\nnn.add(16, activation='sigmoid')\r\nnn.add(32, activation='sigmoid')\r\nnn.add(64, activation='sigmoid')\r\nnn.add(output_shape, activation='sigmoid')\r\n\r\nnn.compile(epochs=1000, display_step=100, batch_size=64, lr=0.05, validation_split=0.2, metrics='accuracy')\r\n\r\nnn.train(train_X, train_Y)\r\nnn.save_model(path='dataset/iris')\r\nprint(nn.evaluate(train_X, train_Y))\r\n```\r\n\r\n## Some important functions of DNN class\r\n\r\n* add(num_of_node, activation='sigmoid')\r\n\t\u003e It will add layers in the neural network\r\n* summary()\r\n\t\u003e Give a summary of the neural network, like: layers, no of nodes, activation function used.\r\n* compile(loss='absolute_error', batch_size=32, optimizer='sgd', epochs=1000,\r\n\tdisplay_step=100, lr=0.01, validation_split=0.0, metrics=None)\r\n\t\u003e It helps in providing the required information to the neural network\r\n* save_weights(path=None)\r\n\t\u003e Save the weights of the neural network\r\n* load_weights(self, path=None)\r\n\t\u003e Load the saved weights\r\n* save_model(path=None)\r\n\t\u003e Save the entire neural network model\r\n* load_model(path=None)\r\n\t\u003e Load the entire neural network model\r\n* predict(X)\r\n\t\u003e Get the result of input datset from the neural network\r\n* train(X, Y)\r\n\t\u003e Train the neural network on the datat provided.\r\n* evaluate(X, Y)\r\n\t\u003e It returns the accuracy of a dataset.\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnikhilroxtomar%2Ffully-connected-neural-network-in-numpy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnikhilroxtomar%2Ffully-connected-neural-network-in-numpy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnikhilroxtomar%2Ffully-connected-neural-network-in-numpy/lists"}