Git Product home page Git Product logo

basic-neural-network's Introduction

Basic-Neural-Network

This is a Neural Network created with reference to the Neural Networks From Scratch Video series by Youtuber Sentdex and his book Neural Networks from Scratch.

Model Explained:

This model first creates a dataset for the required neural network with the help of the function create_data which takes points and classes as input.

This formula returns two arrays X and y, where the data is formed by a pattern in a 2-Dimensional Array in a spiral form, with some added noise for variability.

Then we create a scatter plot with the spiral data, to show how its distributed.

Now to create the layers of the Neural Network, we have the Layer_Dense function, which takes inputs and neurons as input,

with the help of these inputs and neurons we get the weights and biases to be used in the neural network.

Applying the forward function, we get the output with the formula:

Output = Weights*Inputs + Biases

The we apply the Rectified Linear Activation function and update the output. ( Rectified Linear Activation function states that, if x is less than or equal to zero, y is zero else y is equal to x )

Since we are looking for our model to classify, next we use the Softmax Activation function ( In this case, the rectified linear function is unbounded and not normalized with other units, so its values can be anything, without any context and each output is independent of the others.

Due to this lack of context, we use the Softmax Activation function which can take in non-normalized and uncategorized inputs and produce a normalized distribution of probabilities.

Simply put, it is like a generalization for linear regression. )

After using the softmax function, we have an even more efficient output dataset. So, now we calculate the loss by the Sparse Categorical Cross Entropy function ( In linear regression, the most common loss function used is the Mean Squared Error loss, but since we are performing classification on this Neural Network, we use a different loss function.

Since we are getting probabilites as output as a result of the Softmax Activation function, The Cross Entropy loss function is used to compare y(or targets) to y-hat(or predictions) )

Example:

import math
#An example output from the output layer of the neural network
softmax_output = [0.7, 0.1, 0.2]
#Ground truth
target_output = [1, 0, 0]
loss = -(math.log(softmax_output[0])*target_output[0] +
math.log(softmax_output[1])*target_output[1] +
math.log(softmax_output[2])*target_output[2])

#o/p:
#loss = 0.35667494393873245

NOTE: This was just an example taken to explain the categorical cross entropy loss function and it does not use any data from the code so it has no relation with the actual model

Now after applying the loss function, we can simply print the loss, which gives us the output.

basic-neural-network's People

Contributors

devarshh08 avatar

Watchers

 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.