DEV Community

Cover image for When My First ML Model Memorized Instead of Learning (And How I Fixed It)
Urooj Fatima
Urooj Fatima

Posted on

When My First ML Model Memorized Instead of Learning (And How I Fixed It)

When I started working on my first machine learning projects, I thought I was doing everything right.

My model showed almost perfect accuracy during training, and I felt confident about the results.

But as soon as I tested it on new data… everything broke.

That’s when I learned one of the most important lessons in machine learning:
high accuracy doesn’t always mean your model is actually learning.

🧠 The Problem: Overfitting

The issue I faced was overfitting.

Because my dataset was relatively small, the model started memorizing the training data instead of learning general patterns. It captured noise, small variations, and specific details that didn’t apply to new data.

So while performance looked great during training, it completely failed in real-world scenarios.

🛠️ How I Fixed It (From My Projects)

While working on projects like E-commerce Churn Prediction and Diabetes Prediction, I focused on solving this problem step by step.

1. Handling Imbalanced Data with SMOTE

Instead of duplicating data points, I used SMOTE (Synthetic Minority Over-sampling Technique) to create balanced datasets.
This helped the model learn better patterns rather than biasing toward one class.

2. Using Cross-Validation

Rather than relying on a single train/test split, I applied K-Fold Cross Validation.
This gave me a more reliable estimate of how my model performs on unseen data.

3. Controlling Model Complexity

I used algorithms like Random Forest but made sure to tune parameters like tree depth.
Reducing complexity helped prevent the model from memorizing the data.

💡 Key Lesson

The biggest realization for me was:

A model that performs well on training data but fails on new data is not useful.

Generalization matters more than perfect accuracy.

This completely changed how I approach machine learning projects now. I focus more on real performance rather than just improving scores.

📌 Projects I Worked On

Here are some of the projects where I applied these concepts:

  • E-commerce Churn Prediction
  • Diabetes Prediction System
  • Python Practice Projects

(Links available on my GitHub profile)

🚀 Final Thoughts

I’m still learning and improving, but this experience helped me understand machine learning on a deeper level.

If you’re just starting out, don’t chase perfect accuracy — focus on building models that actually work on real data.

💬 Let’s Discuss

What was the biggest challenge you faced when starting machine learning?
Was it overfitting, data preprocessing, or understanding the concepts?

I’d love to hear your experience.

Top comments (0)