Skip to main content

Command Palette

Search for a command to run...

Part 24: Epochs, Batches, and Iterations: How a Model Learns from Data

Understand how a model moves through training data, learns step by step, and improves over multiple rounds.

Updated
•4 min read•View as Markdown
Part 24: Epochs, Batches, and Iterations: How a Model Learns from Data

When we train a machine learning or deep learning model, we don't simply give it all the data once and expect it to learn everything immediately.

Instead, the model processes the training data in smaller groups and goes through the data multiple times.

Three important terms help us understand this training process:

  • Epoch

  • Batch

  • Iteration

Understanding these concepts makes it much easier to understand how neural networks learn.

📚What is a Batch?

A batch is a small group of training examples that the model processes together at one time.

Imagine you have 1,000 students' exam records and want to train a model using them.

Instead of giving all 1,000 records to the model at once, you divide them into smaller groups.

For example:

1,000 records → 10 batches of 100 records each

Each group of 100 records is called a batch.

Real-Life Example

Imagine a teacher has 1,000 answer sheets to check.

Checking all 1,000 at once would be difficult.

So, the teacher checks:

  • 100 papers → Batch 1

  • 100 papers → Batch 2

  • 100 papers → Batch 3

  • ...

  • 100 papers → Batch 10

The same idea is used when training a model.

Batch Size

The number of training examples in one batch is called the batch size.

For example:

Dataset = 1,000 samples
Batch size = 100

Each batch contains 100 samples.

🔄What is an Iteration?

An iteration is one complete step in which the model processes one batch and updates its parameters.

Using our previous example:

1,000 samples
Batch size = 100

The model needs:

1,000 ÷ 100 = 10 iterations

So, 10 iterations are required to process the entire dataset once.

Real-Life Example

Think of the teacher checking 100 papers at a time.

After checking the first 100 papers and learning from the mistakes, that's one iteration.

After the next 100 papers, that's another iteration.

So:

1 Batch processed → 1 Iteration
10 Batches processed → 10 Iterations

🔁What is an Epoch?

An epoch means that the model has gone through the entire training dataset once.

Using our example:

Dataset = 1,000 samples
Batch size = 100

The model processes:

Batch 1 → Iteration 1
Batch 2 → Iteration 2
Batch 3 → Iteration 3
...
Batch 10 → Iteration 10

After all 10 batches have been processed, one epoch is complete.

If we train for 5 epochs, the model goes through the entire dataset 5 times.

🎓Real-Life Example: Preparing for an Exam

Think about preparing for an exam.

You have 100 questions to practice.

You decide to study 10 questions at a time.

  • Batch → 10 questions studied together

  • Iteration → Completing one group of 10 questions and learning from your mistakes

  • Epoch → Completing all 100 questions once

  • 5 Epochs → Going through all 100 questions five times

Each time you repeat the questions, you can improve your understanding based on your previous mistakes.

That's similar to how a model gradually improves during training.

⚙️Why Are These Concepts Important?

These concepts help control how the model learns from data.

A suitable batch size can make training more efficient, while the number of epochs determines how many times the model gets to learn from the entire dataset.

However, simply increasing the number of epochs does not always make a model better. Training for too long can cause overfitting, where the model becomes too focused on the training data and performs poorly on new, unseen data.

🎯Conclusion

Epochs, batches, and iterations help us understand how a model processes data and gradually improves during training. Once these concepts are clear, understanding how a model controls the speed and size of its learning steps becomes much easier.

🚀Coming Up Next

So, how does a model know how wrong its predictions are?

In the next blog, we’ll explore Loss Functions and understand how they measure prediction errors and guide a model toward better learning.