Skip to content

LuluW8071/Neural-Network-From-Scratch-Using-Numpy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Neural-Network-From-Scratch-Using-Numpy

This repository contains code for building and training a neural network from scratch using Numpy, a Python library for numerical computing. The neural network is trained on the MNIST dataset for digit recognition.

Linear Neural Network

Overview

In this project, we implement a simple neural network architecture with one hidden layer using the following steps:

Step Description
Data Loading Load the MNIST dataset containing images of handwritten digits which can be downloaded form here
Data Preprocessing Normalize the images to have pixel values between 0 and 1. One-hot encode labels for classification.
Model Architecture Construct a neural network with an input layer, a hidden layer with ReLU activation, and an output layer with softmax activation.
Training Train the neural network using batch gradient descent with backpropagation. Monitor training for loss and accuracy.
Evaluation Evaluate the trained model on a separate test set to measure its performance.
Prediction Use the trained model to make predictions on new unseen data.

Usage

  1. Clone the repository:
git clone https://github.com/LuluW8071/Neural-Network-From-Scratch-Using-Numpy.git
  1. Install the required dependencies:
pip install -r requirements.txt
  1. Run the training script:
python main.py --train_path "/path/to/train.csv" --test_path "/path/to/test.csv" --plot 1

You can also adjust other parameters for train configs as needed. Here's a table summarizing the command-line arguments accepted by the script:

Argument Description
--train_path Path to the CSV file containing the training data.
--test_path Path to the CSV file containing the test data.
--learning_rate Learning rate to be used for training the model. Default is 0.001.
--epochs Number of epochs for training the model. Default is 150.
--batch_size Batch size to be used during training. Default is 64.
--plot Whether to plot the loss and accuracy curves after training. Set to 1 to plot, 0 otherwise.
--save_path Directory to save the submission file. Default is current_directory.

Sample Demo Run Output

(env) PS D:\Neural-Network-From-Scratch-Using-Numpy> py .\main.py --epochs 150 --plot 1 --train_path ".\train.csv" --test_path ".\test.csv"
Loaded train.csv and test.csv
100%|███████████████████████████████████████████████████████| 150/150 [07:27<00:00,  2.99s/it, accuracy=1, loss=1.3e-5]
Saved inference.csv
  1. After training, the model will make predictions on the test.csv set and save the results in a inference.csv file.

Accuracy and Loss Curves

Figure_1

Also if you want the CNN(Convolutional Neural Network) implementation, you can find the notebook here.

License

This project is licensed under the MIT License - see the LICENSE file for details.


Feel free to report any issues you encounter.
Don't forget to star the repo :)

Releases

No releases published

Packages

No packages published

Languages