Coder Social home page Coder Social logo

cr4ckc4t / neural-network-from-scratch Goto Github PK

View Code? Open in Web Editor NEW
13.0 3.0 5.0 62 KB

A basic neural network with backpropagation programmed from scratch in C++

C++ 100.00%
cpp neural-network from-scratch stl backpropagation stochastic-gradient-descent

neural-network-from-scratch's Introduction

Implementation of a Neural Network from Scratch in C++

Only using the C++ STL (standard template library).

Disclaimer

This was not my idea. I merely followed up on this great tutorial, written by Jason Brownlee, where he explains the steps of programming a neural network from scratch in Python without the use of any library.

Details

Porting the python code from Jason Brownlee to c++ is a great exercise to freshen up a bit on object oriented programming (using classes to represent neurons and layers) and vector handling. It also helps a great deal with understanding how neural networks work on the inside. However, there are many ways that a network like this can be build in c++ and I chose to dive into it without much planning. So the code might not be very beautiful, perfectly encapsulated or easy to comprehend (as a matter of fact, I know it isn't๐Ÿ˜”) but it was fun nevertheless.

Compilation & Usage

This code was built in VisualStudio (2019 v16.9.4) with g++ 8.1.0 (using C++14).

You can either import the code in an empty console project in VisualStudio or compile it directly on the command line with:

g++ -Wall -Wpedantic main.cpp NeuralNetwork.cpp

Simply running it will read the provided csv file from the same directory, train the network and attempt predictions afterwards. Based on the results of the predictions the accuracy is calculated and subsequently printed to stdout.

Result

Using this network on the given seed dataset (and cross-validation) we are able to achieve an approximate accuracy of more than 90%.

The following result was achieved using a learning rate of 0.3 with 500 epochs and 5 neurons in the first hidden layer on a network with one hidden and one output layer.

Screenshot of example output

neural-network-from-scratch's People

Contributors

cr4ckc4t avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  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.