So the perceptron is an artificial neuron that can make a simple decision. Let’s implement one from scratch in Python!
The perceptron has three main components:
Inputs: Each input corresponds to a feature. For example, in the case of a person, features could be age, height, weight, college degree, etc.
Weights: Each input also has a weight which assigns a certain amount of importance to the input. If an input’s weight is large, it means this input plays a bigger role in determining the output. For example, a team’s skill level will have a bigger weight than the average age of players in determining the outcome of a match.
Output: Finally, the perceptron uses the inputs and weights to produce an output. The type of the output varies depending on the nature of the problem. For example, to predict whether or not it’s going to rain, the output has to be binary — 1 for Yes and 0 for No. However, to predict the temperature for the next day, the range of the output has to be larger — say a number from 70 to 90.
Perceptron class by default takes two inputs and a pre-defined weight for each input.
__init__() method inside the
Perceptron class by creating instance variables
self.weights that represent the attributes of a
Assign the parameters
Perceptron object called
cool_perceptron (without any arguments) and print it out to see what it looks like.