Understanding The Perceptron Model

Published on 11/23/2025 by dug22

Average Read Time: 3 Minutes

What is the Perceptron Model?

The perceptron serves as a fundamental unit of logic in artificial neural networks. The perceptron is modified to handle binary classification tasks, distinguishing between two possible outcomes (1 or 0, yes or no, etcetera). While the perceptron has its limitations, its simplicity provides a strong foundation for understanding more complex models. In this article I will be going over how you can build a simple Perceptron model using Python. You can follow along using your prefered IDE like PyCharm or VSCode. I recommend using Jupyter Notebook to follow these exercises.


Preparing Our Dataset

The Perceptron Model requires a dataset of corresponding inputs and weights. Inputs can be predefined as x0, x1, x2, where as weights can be predefined as w0, w1, w2, each assigned a corresponding value. These weights dictate the influence each input value has on the overall weighted sum. To accomplish something like this in Python you can simply create a simple dictionary of inputs and weights with an array of corresponding values.

data = {"Inputs": [0.6, 0.4, 0.4], "Weights": [0.4, 0.3, 0.3]}

Multiplying Inputs and Weights And Getting The Sum of Products

Multiplying each input by its corresponding weight and then summing these products is crucial in the perceptron model because this operation determing the activation value, the number that decides whether the perceptron outputs a 1 or 0. Each weight represents how important its input is. By multiplying and summing, the perceptron will produce a single combined value that reflects all inputs and their influences. From this value is then compared to a specific threshold (or passed through a given activation function) to determine the final output.

corresponding_products = [input_value * weight_value for input_value, weight_value in zip(data["Inputs"], data["Weights"])]
print("Corresponding Products:",corresponding_products) 

Output

Corresponding Products: [0.24, 0.12, 0.12]

Take the array of corresponding products and find the sum of it. In this case the sum of the coresponding products is 0.48

sum_of_products = sum(corresponding_products)
print("Sum of Corresponding Products:", sum_of_products)

Output

Sum of Corresponding Products: 0.48

Applying The Activation Function

It is very crucial to check if the sum exceeds a specific threshold also known as the bias. To evaluate whether the threshold has been met, we can use an activation function called the step function. Think of the step function as 1 if x > bias, 0 otherwise. Lets bring this to life by creating a function called step_function with the given parameters weighted_sum and bias. Our bias/threshold value will be 0.5.

def step_function(weighted_sum, bias):
  return 1 if weighted_sum > bias else 0
step_function_result = step_function(sum_of_products, 0.5)
print("Step Function Result:", step_function_result)

Output

Step Function Result: 0

Perceptron Visual

Attached is a visual representation that illustrates how the Perceptron model works by connecting all the key pieces together.


Sources

  1. Perceptron Algorithm with Code Example - ML for beginners! By Python Simplified
  2. What is a Perceptron? – Basics of Neural Networks By Anjali Bhardwaj