Skip to main content

Someone wanted to learn this too, so Grasp built them a personal learning path.

You can keep exploring this one or create your own

Single Neuron: Structure and Output Calculation

Hello! Welcome to the second module of our course, Neural Networks from Scratch.

In the previous module, you built a strong foundation in practical machine learning using Scikit-learn. You mastered the entire workflow, from data preprocessing to hyperparameter tuning, and learned how to encapsulate these steps into robust, reproducible Pipelines. This is a critical skill for any machine learning practitioner.

Now, we're going to shift our focus from using pre-built models to understanding what goes on inside them. We will open the "black box" of deep learning and build our own neural network using only Python and NumPy. This will provide you with a deep, first-principles understanding that is essential for becoming a proficient AI engineer.

This first lesson begins with the most fundamental building block of any neural network: the artificial neuron. By the end of our session, you will be able to explain the structure of a single neuron and compute its output given a set of inputs, weights, bias, and an activation function.

1. From Linear Models to a Neuron

You're already familiar with linear models from your machine learning theory background. A simple linear regression equation for multiple inputs looks like this:

This exact calculation—a weighted sum of inputs plus an intercept (or bias)—forms the core of an artificial neuron. Let's formalize this structure.

2. The Anatomy of an Artificial Neuron

An artificial neuron (also known as a perceptron) is a simple computational unit that takes inspiration from its biological counterpart. It processes information through a few key steps.

Structure of a Neuron
An artificial neuron takes multiple inputs (x), multiplies each by a weight (w), sums them up, adds a bias (b), and then passes the result through an activation function (f) to produce a single output (y).

As the diagram shows, a neuron has the following components:

  • Inputs (): These are the features from your dataset that are fed into the neuron. For the very first layer of a network, this could be the pixel values of an image or columns from a tabular dataset.
  • Weights (): Each input has an associated weight. This weight determines the importance of that input. A larger weight means the input has more influence on the neuron's output. These are the main parameters the network "learns" during training.
  • Bias (): This is a single, extra parameter that is added to the weighted sum. The bias allows the neuron to shift the output of the activation function up or down. A key role of the bias is to allow the neuron to produce a non-zero output even when all inputs are zero.
  • Activation Function (): The total sum () is passed through an activation function. This function introduces non-linearity, which is crucial. Without it, a multi-layer network would be mathematically equivalent to a single, simple linear model, and would be unable to learn the complex patterns required for tasks like image recognition.

3. Calculating the Neuron's Output

The process of calculating a neuron's output from its inputs is called feedforward. It's a two-step calculation.

To dive into this process, let's go through a clear, step-by-step explanation.

Machine Learning for Beginners: An Introduction to Neural Networks

This article by Victor Zhou provides a fantastic, beginner-friendly walkthrough of the neuron's calculation. It breaks down the process and provides a simple, concrete example.

Read the first section, '1. Building Blocks: Neurons', including the subsection 'A simple Example'. Pay close attention to the three steps outlined: multiplying inputs by weights, summing them with a bias, and passing the result through an activation function. Work through the provided numerical example to solidify your understanding.

As you've just read, the calculation unfolds as follows:

  1. Calculate the Net Input (Weighted Sum): First, we compute the dot product of the input vector and the weight vector , and then add the bias . This value is often denoted by .

  2. Apply the Activation Function: Next, we pass the net input through an activation function, , to get the final output . The sigmoid function, , which squashes any real number into the range (0, 1), is a common choice for introductory examples.

The video below offers a great visual walkthrough of this exact process.

The Essential Main Ideas of Neural Networks

Let's watch a visual demonstration of the feedforward calculation. This clip from the StatQuest channel clearly shows how an input is processed by a neuron, step-by-step. It also formalizes the terminology we've just discussed.

Watch the two segments: 08:08 - 12:30 and 17:11 - 17:45. The first part walks through the calculation: input * weight + bias, followed by applying the activation function. The second part explicitly defines the terms 'weights' and 'biases'.

4. Practice: Your Turn to Calculate

Now it's time to put this knowledge into practice. This will confirm you've met today's learning objective.

Problem:
Consider a neuron with 3 inputs that uses the sigmoid activation function. Its parameters are:

  • Weights:
  • Bias:

If the neuron receives the input vector , what is its final output?

Take a moment to calculate it yourself before checking the solution below.

Click here for the step-by-step solution

Step 1: Calculate the net input .

Step 2: Apply the sigmoid activation function to .

Using a calculator, .

So, the neuron's output is approximately 0.711.

Conclusion

In this lesson, you've taken the first crucial step into the world of deep learning. You've deconstructed the artificial neuron, the fundamental unit that powers even the most complex models like GPT-4.

Key Takeaways:

  • An artificial neuron is a simple computational unit that calculates a weighted sum of its inputs, adds a bias, and passes the result through a non-linear activation function.
  • The neuron's adjustable parameters, which are "learned" during training, are its weights and bias.
  • The activation function is essential for introducing non-linearity, enabling neural networks to learn complex relationships in data.
  • The process of computing an output from a set of inputs is called feedforward.

We focused on the sigmoid function today for its simplicity. However, there are several other activation functions, each with unique properties. In our next lesson, we will explore and compare the most common ones—Sigmoid, Tanh, and ReLU—and understand when and why to use each. This will be our next step toward building a complete neural network layer.

Can't find a good explanation? Sign up and we'll make it for you

Sign up