Giter VIP home page Giter VIP logo

mlp-classifier's Introduction

MLP-Classifier

Multi-Layer Perceptron Classifier 🤗

Implementation of Multi-Layer Perceptron Artificial Neural Network in Python 3. Heavily inspired by Rising Odegua's MLP articles and Patrick David's All the Backpropagation derivatives

About

Neuron

It accepts list of variables as an input. Those variables are being multiplied by corresponding weights. The result of multiplication is summed and provided as an input to the activation function, which calculates an output number

Perceptron

It's a neural network build with a single neuron

Neural network

Consists of multiple neurons

Layer

Layer is a group of neurons

Layers between input and output layers are called hidden layers

First layer - input layer

It is not counted as a layer in a network

Number of nodes in the first layer equals number of features in the input data

Last layer - output layer

Number of nodes (variables) in output layer depends on type of desired prediction

Weight

It represents how a given feature is important. It is multiplied by a feature's value

Bias

It is a starting value for a given neuron. It is added to sum of multiplications of weights and features values.

Activation function

It determines whether a neuron's contribution to the neural network should be taken into account or not

Forward propagation

It is a training process for a network. It consists of the following steps:

  1. Multiply each input feature and randomly generated corresponding weight of the first layer, sum them up and add the bias
  2. Use this result as an input to activation function
  3. Use the output from activation function as a features for the next weights and repeat this step until the last layer
  4. Pass the last result to the output activation function
  5. Compute the loss function by using last result (prediction) and actual (true) values

Backward propagation

It is about learning process in neural network through improving network's weights and biases.

A network checks the output for various weights and evaluates them using loss function. Decrease of loss means that weights are getting better

Backpropagation uses derivatives of loss with respect to all previously calculated values - weights, biases and activation function results

Input values are not differentiated

Backward propagation steps, based on Patrick David's All the Backpropagation derivatives:

  1. Derivative with respect to (wrt) activation function $\frac{\partial L}{\partial a}$:

Derivative of the negative log likelihood function (cross-entropy):

$$[yln(a) + (1-y)ln(1-a)] = $$

$$[-yln(a) - (1-y)ln(1-a)] = $$

$$\frac{\partial L}{\partial a} = [\frac{-y}{a} - (-)\frac{(1-y)}{(1-a)}]$$

$$\frac{\partial L}{\partial a} = [\frac{-y}{a} + \frac{(1-y)}{(1-a)}]$$

  1. Derivative of sigmoid $\frac{\partial a}{\partial z}$:

Derivative is $$\frac{1}{1+e^{-z}} = ... = sig(z) * (1 - sig (z))$$

  1. Derivative wrt linear function

Linear function is $z = W*X + b$, where $W$ represents weights, $X$ is input and $b$ is bias

Derivative is $a - y$

  1. Derivative wrt weights $\frac{\partial z}{\partial w}$:

$z = w^T*X + b$

Derivative is $x$

  1. Derivative wrt bias $\frac{\partial L}{\partial b}$:

Derivative is $a - y$

Optimization

It means looking for the best possible weights and biases in the network

Training

Repeat these three steps:

  1. Forward propagation
  2. Backward propagation
  3. Update weights with calculated gradients

Resources

When implementing the network, I based on these great online resources:

Author

© Copyright Jędrzej Paweł Maczan. Made in Poland, 2022 - 2023

mlp-classifier's People

Contributors

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