Giter Club home page Giter Club logo

neural-network-on-mnist-with-numpy-from-scratch's Introduction

Neural Network on MNIST with NumPy from Scratch

Implement and train a neural network from scratch in Python for the MNIST dataset (no PyTorch).

Project Description:

Implement and train a neural network from scratch in Python for the MNIST dataset (no PyTorch). The neural network should be trained on the Training Set using stochastic gradient descent. It should achieve 97-98% accuracy on the Test Set.

Implementation

In my code, I defined an object NN to represent the model and contain its parameters. I first initialize a random set of parameters, and then I use stochastic logistic regression algorithm to train the neural network model with data replacement. Then I test the data based on the training dataset to get the accuracy score. Below are the related parameters I used.

# set the number of iterations
num_iterations = 200000
# set the base learning rate
learning_rate = 0.01
# size of hidden layer
hidden_size = 300

Note that I implemented a learning rate schedule as follows:

Figure_0

I wrote 8 methods including __Softmax(z), __activfunc(self,Z,type = 'ReLU'), __cross_entropy_error(self,v,y), __forward(self,x,y), __back_propagation(self,x,y,f_result), __optimize(self,b_result, learning_rate), train(self, X_train, Y_train, num_iterations = 1000, learning_rate = 0.5), testing(self,X_test, Y_test) to handle initialization, model fitting and testing.

Test Accuracy

The test accuracy and value of loss function with respect to the number of iterations within one time of modeling are shown as follows. Note the test eventually has achieved an accuracy score of around 97%. (Sample test: accuracy = 97.2%)

Figure_1

Figure_2

neural-network-on-mnist-with-numpy-from-scratch's People

Contributors

yawen-d avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.