Computing — March 29, 2026 — Edu AI Team
If you want to learn how to build a neural network from scratch in Python, the simplest path is this: create input data, define weights and biases, pass the data through a few math steps, measure the error, and then adjust the weights little by little so the network improves. You do not need advanced maths or complex software to understand the basics. In this guide, we will build a tiny neural network in plain Python and explain every part in simple language.
A neural network is a computer system inspired loosely by the human brain. It takes in information, looks for patterns, and makes a prediction. For example, a neural network might decide whether an email is spam, whether a photo contains a cat, or whether a customer is likely to buy a product. The good news for beginners is that you can learn the core idea with a very small example.
At its core, a neural network is just a series of calculations. It starts with inputs, which are the pieces of information you give it. It then multiplies those inputs by weights, adds a bias, and sends the result through an activation function. That activation function helps the network handle more complex patterns.
Think of it like this:
For a beginner example, imagine we want a network to learn a simple pattern. We will teach it that these inputs should lead to these outputs:
This is close to a basic logical rule: if at least one input is 1, the output should be 1.
Inputs are the numbers we feed into the network. In our example, each training example has two inputs.
Weights are adjustable numbers. They control how strongly each input affects the prediction. At first, the weights are random. During training, they get updated.
A bias is an extra number added to the calculation. It helps the network shift its decision boundary, which is just a simple way of saying it helps the model make better choices.
An activation function changes the raw output into something more useful. We will use the sigmoid function because it is easy to understand. It turns any number into a value between 0 and 1, which is helpful for predictions like “no” or “yes”.
Training means showing the network examples, checking how wrong it is, and adjusting the weights and bias to reduce that error. This process is repeated many times.
Below is a very small neural network with one layer. We are not using TensorFlow, PyTorch, or any heavy library. This is useful because it helps you see what is happening under the hood.
Step 1: Import Python tools
We will use NumPy, a popular Python library for working with numbers and arrays.
import numpy as np
Step 2: Create the sigmoid function
def sigmoid(x):
return 1 / (1 + np.exp(-x))
Step 3: Create the derivative
The derivative helps us know how much to change the weights during training.
def sigmoid_derivative(x):
return x * (1 - x)
Step 4: Prepare the training data
X = np.array([[0, 0],
[0, 1],
[1, 0],
[1, 1]])
y = np.array([[0],
[1],
[1],
[1]])
Step 5: Set random starting weights and bias
np.random.seed(42)
weights = np.random.rand(2, 1)
bias = np.random.rand(1)
Step 6: Train the network
learning_rate = 0.1
for epoch in range(10000):
# Forward pass
inputs = np.dot(X, weights) + bias
outputs = sigmoid(inputs)
# Error
error = y - outputs
# Backward pass
adjustments = error * sigmoid_derivative(outputs)
weights += np.dot(X.T, adjustments) * learning_rate
bias += np.sum(adjustments) * learning_rate
Step 7: Test the network
print("Final weights:")
print(weights)
print("Final bias:")
print(bias)
print("Predictions:")
print(sigmoid(np.dot(X, weights) + bias))
The forward pass means the network takes the input values and makes a prediction. It does this with:
np.dot(X, weights) + bias
This multiplies each input by its weight and then adds the bias. After that, the sigmoid function squeezes the result into a number between 0 and 1.
For example, if the network outputs 0.92, that means it is very confident the answer should be 1. If it outputs 0.08, it is very confident the answer should be 0.
The error is simply:
error = y - outputs
If the correct answer is 1 but the network predicts 0.4, the error is 0.6. That tells the network it needs to improve.
The backward pass is the learning step. The network looks at the error and adjusts the weights and bias. This is the heart of learning in neural networks.
We use:
adjustments = error * sigmoid_derivative(outputs)
This tells us how much each weight should move. Then we update the weights and bias using the learning rate.
The learning rate controls the size of each step. A small learning rate means slow but careful learning. A large one means faster learning, but it may overshoot and miss the best answer.
After enough training rounds, the outputs should be close to:
These are not exact because the starting weights are random, but they should be very close to the correct pattern. In other words, the network has learned.
If libraries like TensorFlow and PyTorch already exist, why start from scratch?
Because building one yourself helps you understand:
It is a bit like learning basic arithmetic before using a calculator. Once you understand the simple version, modern AI tools make much more sense.
If you want beginner-friendly lessons that explain Python, machine learning, and neural networks step by step, you can browse our AI courses to find a course that matches your level.
Neural networks expect data in a certain structure. If your rows and columns are mixed up, your code may fail or give strange results.
A neural network usually gives probabilities, not perfect 0s and 1s. So 0.93 is a strong “yes,” even if it is not exactly 1.
If you stop too early, the network may not learn enough. In our example, 10,000 training rounds is reasonable because the dataset is tiny.
Many beginners jump straight into image recognition or chatbots. That can feel overwhelming. A tiny network like this is a much better first step.
Once you understand a single-layer neural network, the next steps are:
You may also want to strengthen your Python basics first. That often makes machine learning much easier to understand. If you are just getting started and want a structured path instead of piecing together random tutorials, you can register free on Edu AI and explore beginner-friendly learning tracks.
Building one small neural network will not make you an AI engineer overnight, but it gives you a very strong foundation. Many people who switch into AI or data careers begin with simple projects exactly like this one. The key is to understand the logic before moving to larger tools and real-world projects.
For beginners, the best learning order is usually:
Now you know the basic answer to how to build a neural network from scratch in Python: start with inputs, weights, a bias, an activation function, and a training loop that slowly reduces error. Keep it small, repeat the process, and focus on understanding each step.
If you would like help turning these first concepts into practical skills, Edu AI offers beginner-focused courses in Python, machine learning, and deep learning. You can browse our AI courses or view course pricing to choose a learning path that fits your goals.