✎ Edit content·DAY 034 · POST 5 OF 5 · Common Mistakes

Overfitting & Regularization

Machine Learning · 12 slides
DAY 034 · POST 5 OF 5
(REMINDER)
DAY 034
Overfitting: Common Mistakes
@saurav_dnj_24github.com/SauravDnj · linkedin.com/in/sauravdnj
1 / 12

Theme

Palette

Download

4K — sharpest, slowest
🎬 Video options
Preparing preview…
Live preview · loops the “none” effect
All rendering runs in your browser. No server, no cost, no upload. MP4/WebM = full motion + effects · GIF = lightweight loop · PNG/PDF = static for the Instagram & LinkedIn carousel.

Caption (tap to copy)

📖 Deep dive (full written explanation)

The slides stay clean and scannable. Here's the in-depth explanation behind each one — great for the blog version, show notes, or studying the topic properly.
Slide 1 · Overfitting: Common Mistakes

This final post is the field guide to the mistakes that bite real practitioners — including experienced ones — when fighting overfitting. The subtle theme is that most overfitting disasters aren't caused by ignorance of regularization techniques. They're caused by using those techniques incorrectly, or by trusting a number that was already poisoned by a process error before the model ever saw it.

Each mistake here has the same insidious property: it makes an overfit or compromised model look perfectly healthy. Learning to spot these traps is what separates someone who can recite the techniques from someone who can actually ship a model that holds up in production.

Slide 2 · Tuning λ on the test set

Tuning your regularization strength on the test set is the cardinal sin, and it's easy to commit without realizing it. The moment you adjust lambda (or C, or dropout probability) to maximize test accuracy, the test set stops being an unbiased estimate of generalization. You've effectively turned it into a second validation set, and its score becomes optimistically biased — it now reflects how well you tuned to it, not how the model will perform on truly new data.

The fix is discipline about which data does which job. Tune regularization on a dedicated validation set or via cross-validation, both of which can be used repeatedly. Reserve the test set for a single, final measurement after every hyperparameter is frozen. That one-shot use is the entire reason the test score can be trusted.

Slide 3 · Forgetting to scale features

Forgetting to scale features before L1 or L2 is a quiet but serious error, because these penalties operate on weight magnitudes. Imagine one feature measured in thousands (like income) and another in fractions (like a ratio). To have equivalent effect on predictions, the income feature needs a tiny weight and the ratio feature needs a large one — purely because of their units, not their importance.

Since the penalty punishes large weights, it will disproportionately penalize the feature that happens to need a large weight, regardless of how useful that feature actually is. The result is regularization that distorts the model based on measurement units rather than predictive value. Standardizing all features to comparable scales before applying L1 or L2 is therefore mandatory, not optional.

Slide 4 · Scale, then regularize

This code slide shows the correct, leak-free way to combine scaling and regularization using a pipeline. The StandardScaler and the regularized model are wrapped together with make_pipeline. When you call fit, the scaler computes its mean and standard deviation from the training data only, then those exact statistics are reused to transform any future data.

The critical property is that this prevents leakage. If you scaled the full dataset before splitting, information about the test set's distribution would bleed into the training process, inflating your scores. Inside a pipeline, the scaler is fit strictly on training data within each fold, so cross-validation and final evaluation stay honest. The pipeline pattern is the standard professional way to ensure preprocessing never leaks — adopt it as a default habit.

Slide 5 · Data leakage

Data leakage is the most dangerous mistake in this post because no amount of regularization can fix it, and it produces gloriously misleading scores. Leakage is any situation where information that wouldn't be available at prediction time sneaks into training. The two classic forms are preprocessing leakage — scaling, imputing, or selecting features on the full dataset before splitting — and target leakage, where a feature secretly encodes the label you're trying to predict.

A leaked model looks spectacular in evaluation and then collapses the moment it's deployed, because the leaked information simply isn't present in production. The defense is structural vigilance: split your data first, do all preprocessing inside cross-validation folds or pipelines, and scrutinize any feature that seems suspiciously predictive — it may be leaking the answer.

Slide 6 · How leakage fools you

This decision tree encodes the diagnostic logic for trusting a score, walking through the two leakage-style failures in order. First question: did any test information touch training — through preprocessing on the full dataset, or a leaked feature? If yes, the score is inflated and untrustworthy, full stop. If no, ask the second question: was the regularization strength tuned on the test set? If yes, the test score is now optimistic because it was used for selection. Only if both answers are no is the score genuinely honest.

Running a model's evaluation through these two questions before believing any number is a fast, powerful habit. Most cases of 'too good to be true' results trace back to one of these two branches, and catching them early saves you from shipping a model whose reported performance was never real.

Slide 7 · Over-regularizing

Over-regularizing is the mistake of treating regularization as 'more is better' rather than as a dial to be tuned. If you crank the penalty too high, you swing past the sweet spot and straight into underfitting: the model becomes too constrained to capture the real signal, and both training and test scores sag together. The wide train-test gap of overfitting is gone, but it's been replaced by uniformly poor performance.

This is why the bias-variance U-curve matters so much in practice. There's an optimal regularization strength, and both too little and too much hurt you. The remedy is to tune in both directions — if both scores are low and close, you've over-regularized and should reduce the penalty; if training is high and test is low, you need more. Never assume maximum regularization is safe.

Slide 8 · 'Just add more layers'

The reflex to 'just add more layers' or more capacity when a model underperforms often makes overfitting worse, and this slide pushes back on that instinct. Adding parameters increases the model's ability to memorize, which is the last thing you want if the real problem is generalization. More capacity demands more data and stronger regularization to stay healthy — it's not a free upgrade.

The disciplined approach is to first diagnose why the model is underperforming. If it's overfitting (high train, low test), more capacity will deepen the wound; you need regularization or more data instead. Only when you've confirmed the model is genuinely underfitting — too simple to capture the pattern, with low scores everywhere — does adding capacity make sense. Diagnose before you prescribe.

Slide 9 · The two ditches

This comparison frames the two ditches you can fall into, making the symmetric nature of the failure modes explicit so you always know which way to steer. Too little regularization, on the left: training score far exceeds test, the model memorizes noise, it's brittle in production, and the fix is to add a penalty or more data. Too much regularization, on the right: training and test are close but both low, the model misses real signal, it underfits, and the fix is to reduce the penalty.

The value of holding both ditches in mind is that diagnosis becomes directional. You're not just asking 'is something wrong?' but 'which way is it wrong, and therefore which way do I correct?' This turns tuning from trial-and-error into a guided adjustment toward the balanced center.

Slide 10 · Ignoring the gap

Ignoring the train-test gap entirely is, paradoxically, the most common mistake of all — and it underlies most of the others. Many practitioners look at a single accuracy number, celebrate it, and move on, never comparing in-sample and out-of-sample performance. But a number in isolation is meaningless for diagnosing overfitting; the gap between training and test is the actual gauge.

If you only ever look at training accuracy, you are flying blind — you literally cannot see overfitting happening. The fix is a non-negotiable habit established back in Post 1: every time you evaluate a model, look at both scores and the gap between them. This one discipline catches the majority of overfitting problems before they ever reach production, which is why it's worth treating as a reflex.

Slide 11 · Do this instead

These corrective habits distill the entire post into a do-this-instead checklist. Tune regularization on validation and touch the test set exactly once. Scale features inside a pipeline so preprocessing is fit on training data only. Split before any preprocessing to prevent leakage. Treat lambda as a dial and be willing to tune it in both directions, not just upward. And always watch the train-test gap rather than any single number.

Followed together, these habits make the whole workflow from Post 4 robust against the subtle process errors that produce misleading results. They're not complicated, but they're easy to skip under time pressure — which is exactly when they matter most. Bake them in as defaults and you'll avoid the traps that quietly ruin otherwise-good models.

Slide 12 · Save this. Follow for Day 35.

This closes both the post and Day 34. You now have the full arc: what overfitting and regularization are, why they matter, how the mechanisms work, how to apply them in code, and the mistakes that quietly sabotage the whole effort. Together these five lenses give you a complete, practical command of one of the most important skills in applied machine learning.

The series moves on to a new topic next, but the payoff from this day is durable: every model you build from here on will be one you measure honestly, regularize deliberately, and trust because you've ruled out the failure modes. That's the difference between a model that aces the test and one that survives contact with real data — and now you know how to build the second kind.

🎨 AI image prompt (matches this theme + palette)

Paste into Midjourney, DALL·E, Ideogram, etc. to generate an on-brand image, then upload it on the Edit content page. The prompt updates automatically with the selected theme + palette.