Posts

Showing posts from December, 2019

Perceptron in Python and C++

Image
Intro In this post, I’m going to cover the Perceptron Algorithm and compare its implementation in Python and C++. Perceptron Explanation The perceptron algorithm performs binary classifications by using a signed weighted sum of an input point to predict one of two output classes. The weights used are found by fitting a linear decision boundary to the training data. In order for the perceptron to achieve 100% accuracy, the data must be linearly separable. Formally, the perceptron prediction function f can be represented as: Predictions are made using the sign function as the activation function: Training the perceptron is an iterative process. At a high level, the algorithm: Initialize weights to be zeroes For a predefined # of epochs makes a prediction for each misclassified point updates the weight vector The update rule for the weight matrix is given by the following: Error is calculated with the equation below where y is the label for each input x...