How to avoid overfitting on a simple feed forward network
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.
Introduction
When working with machine learning models, particularly neural networks, one critical issue that can arise is overfitting. Overfitting occurs when a model learns not just the underlying distribution of the training data but also the noise, leading it to perform poorly on unseen data. In this article, we'll explore how to avoid overfitting on a simple feedforward network, providing technical explanations and offering practical solutions.
Understanding Overfitting
What is Overfitting?
Overfitting is a modeling error that occurs when a machine learning model captures the noise of the training data instead of its actual distribution. This results in a model that performs well on the training data but poorly on new, unseen data.
Symptoms of Overfitting
• High accuracy on training data but low accuracy on validation or test data. • Increasing gap between training and validation loss/accuracy over epochs.
Strategies to Avoid Overfitting
We can employ various techniques to mitigate overfitting in a feedforward neural network.
1. Regularization
Regularization adds a penalty to the loss function to discourage overly complex models. There are two common types:
• L1 Regularization: Adds a penalty equal to the absolute value of the magnitude of coefficients. It can reduce some weights to zero, effectively performing feature selection.
• L2 Regularization: Adds a penalty equal to the square of the magnitude of coefficients, also known as weight decay. This encourages smaller network weights.
Mathematical Formulation for L2 Regularization:
Where is the regularization parameter, represents weights, and is the total number of weights.
2. Dropout
Dropout is a simple yet powerful technique. It randomly "drops" or sets some neurons to zero during training, which prevents neurons from co-adapting too much.
Example Implementation:
Related reading
- How to avoid overfitting on a simple feed forward network
- How to balance classification using DecisionTreeClassifier?
- How to balance unbalanced classification 11 with SMOTE in R
- How to build a attention model with keras?
- How to avoid reinstalling packages when building Docker image for Python projects?
- How to build hybrid model of Random Forest and Particle Swarm Optimizer to find optimal discount of products?
- How to build a lift chart a.k.a gains chart in Python?
- How to build a multiple input graph with tensor flow?

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.