Featured Article

How to Train a Simple Neural Network: Easy Step-by-Step Guide

Kenneth Jul 13, 2026

Embarking on the journey of neural networks? Let's start with the basics and learn how to train a simple neural network. This fundamental skill provides a strong foundation for your deep learning endeavors.

How Neural Networks Learn
How Neural Networks Learn

Neural networks are at the heart of artificial intelligence, enabling machines to learn and make informed decisions. By the end of this guide, you'll be able to create, train, and evaluate your first neural network.

How to create a Neural Network in JavaScript in only 30 lines of code
How to create a Neural Network in JavaScript in only 30 lines of code

Understanding Neural Networks

A neural network is a series of algorithms designed to recognize patterns. It's inspired by the human brain, where neurons transmit information. The three fundamental components of a neural network are:

How to build and run your first deep learning network
How to build and run your first deep learning network
  • Neurons: the basic processing unit
  • Layers: groups of interconnected neurons
  • Connections: paths that connect neurons together

The brain's billions of interconnected neurons make intricate connections to process and interpret information. Similarly, artificial neural networks mimic this architecture to perform tasks.

Make Your Own Neural Networks
Make Your Own Neural Networks

Neural Network Architecture

Neural networks have an input layer, one or more hidden layers, and an output layer. Each layer is comprised of several interconnected nodes. Here's a simple architecture representation:

Layers Neurons
Input 6
Hidden 4
Output 3
What are physics informed neural networks used for?
What are physics informed neural networks used for?

For this tutorial, let's consider a neural network with 6 input features, 4 hidden neurons, and 3 output classes.

The Role of Weights and Biases

Each connection between neurons has an associated weight. These weights determine the influence of the input value on the output. They're randomly initialized initially. Biases, on the other hand, are constants added to the weighted sum before activation. Together, weights and biases help a neural network make predictions.

How to implement the backpropagation using Python and NumPy
How to implement the backpropagation using Python and NumPy

Building and Training the Network

Now that we understand the basics, let's build and train our simple neural network in Python using the Keras framework.

neural network
neural network
How CNN (Convolutional neural network) works
How CNN (Convolutional neural network) works
A Neural Network fully-coded in Numpy and Tensorflow
A Neural Network fully-coded in Numpy and Tensorflow
Neural Networks Explained from Scratch using Python
Neural Networks Explained from Scratch using Python
How backpropagation works, and how you can use Python to build a neural network
How backpropagation works, and how you can use Python to build a neural network
Mastering Convolutional Neural Networks: A Beginner Guide
Mastering Convolutional Neural Networks: A Beginner Guide
Understanding Transformer Neural Networks: A Game-Changer in AI
Understanding Transformer Neural Networks: A Game-Changer in AI
two diagrams that show how the network works
two diagrams that show how the network works
A beginner's guide to AI: Neural networks
A beginner's guide to AI: Neural networks

Importing Required Libraries

from keras.models import Sequential
from keras.layers import Dense
import numpy as np

Preparing the Data

Load your dataset and preprocess it (normalize, normalize, or split into training and test sets). Here, we'll use a simple Iris dataset:

from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split

iris = load_iris()
X_train, X_test, y_train, y_test = train_test_split(iris.data, iris.target, test_size=0.25)

Defining the Model Architecture

We'll create a sequential model with an input layer (6 neurons), a hidden layer with 4 neurons, and an output layer (3 classes).

model = Sequential()
model.add(Dense(4, input_dim=6, activation='relu'))
model.add(Dense(3, activation='softmax'))

Compiling the Model

Specify the optimizer, loss function, and evaluation metrics:

model.compile(loss='sparse_categorical_crossentropy', optimizer='adam', metrics=['accuracy'])

Training the Model

Train the model with the training data:

model.fit(X_train, y_train, epochs=100, batch_size=10)

Evaluating the Model

Evaluate the model's performance on the test data:

loss, accuracy = model.evaluate(X_test, y_test)

The accuracy will tell you how well your neural network is able to classify the Iris flowers in the test set. As you train your models on more complex and larger datasets, you'll find this process becomes increasingly valuable.

Just like the human brain learns from experience, neural networks learn from data. So conquĂȘte new territories by expanding your knowledge and exploring different datasets. Happy learning, and stay curious!