← the late compiler
C_000334 · machine learning · foundation

Ridge and Lasso Regression

Regularised linear regression: ridge penalises squared coefficients, lasso penalises absolute values.

Step 1 of 4

In words

What it is, why it matters, and what it is like.

Why am I learning this?

This is the first concept you'll learn that directly controls how well a model performs on new data. Without it, your models will memorize your training data and fail in the real world. Mastering ridge and lasso unlocks the rest of the 'Regularization' topic: dropout, early stopping, data augmentation. From there you'll go to Deep Learning and Model Evaluation. In practice, any serious machine learning you do — from predicting house prices to building a recommendation system — will use these techniques to keep your models honest.

The idea, in plain terms

You have a set of data points and you want to draw a line through them that predicts something new. But if you give that line too much freedom — too many knobs to turn — it will twist and bend to touch every single data point, even the noise. That's overfitting: perfect on your training data, useless on anything new. Ridge and Lasso are two ways to pull those knobs back. They add a cost to having large knob settings, so the model learns to keep them small. Think of it as a budget: you have 100 rupees to spend on your knobs. Ridge charges you per rupee you spend, so you buy only the knobs that matter. Lasso charges you per knob you turn on at all, forcing you to switch most of them off entirely. The result is a simpler, more reliable line.

An analogy

Imagine you're moving to a new apartment and you have to decide which of your 50 boxes to take with you. You have two strategies. Ridge: you can take all 50 boxes, but you pay a storage fee for each kilogram. So you take the heavy ones because they're essential, and you take the light ones but you wish you could leave them behind — you end up with a little bit of everything. Lasso: you have a flat fee per box you take, so you only take the boxes you truly need. The rest stay in storage (their coefficient becomes zero). In machine learning, your 'boxes' are your predictor variables. Ridge shrinks all their influence but keeps them all. Lasso selects a few and discards the rest. But the analogy breaks down: in real moving, you can't take a fraction of a box. In ridge, you actually shrink a coefficient to 0.7 or 0.2 — you keep a little of every variable. And lasso doesn't just pick a box and leave it — it actually forces the coefficient to zero, which is like throwing the box away entirely. So ridge is gentle, lasso is decisive.

Definition

Ridge and Lasso are regularized linear regression methods that add a penalty to the size of the coefficients: ridge adds the sum of squared coefficients, lasso adds the sum of absolute values, and this penalty forces the coefficients to be smaller (ridge) or zero (lasso).

Where this sits

You haven't learned anything else yet, so this is your gateway. The only math we'll use is arithmetic — adding, subtracting, multiplying, squaring, and taking absolute values. You'll need to understand what a coefficient is (the number that multiplies a variable in a linear equation). If you've ever seen y = 2x + 1, the 2 and 1 are coefficients. We'll extend that idea. Everything later — the full world of machine learning — builds on this foundation.

Signal from the Frontier

Get the next essay on mind, machine, and meaning

Essays at the intersection of AI, philosophy, and Indian governance. No promotional content.

We'll send a one-click sign-in link to confirm. No password needed.

Views expressed are personal and do not represent the Government of India or the Government of Uttarakhand.