Interactive Explainer
MAP = Likelihood × Prior
“Add a regularizer to the loss” sounds like a hack. It isn't. Put a prior on your parameters, multiply it by the likelihood, and maximize the product — that's the MAP estimate, and the regularizer falls out automatically. This page draws all three distributions in parameter space so you can see the MAP sit between the data's answer (MLE) and the prior's pull toward zero.
Two peaks, one product
Take a tiny model with just two weights $\theta = (\theta_1, \theta_2)$. The likelihood $p(\text{data}\mid\theta)$ is a bump centered on the value that best fits the data — the MLE. The prior $p(\theta)$ is a bump centered at the origin, encoding “keep the weights small.” Bayes multiplies them into the posterior:
Take $-\log$ of both sides and the product becomes a sum — a data-fit term plus a penalty term:
A Gaussian prior gives $-\log p(\theta) \propto \lVert\theta\rVert_2^2$ — that's ℓ₂ regularization (ridge). A Laplace prior gives $-\log p(\theta) \propto \lVert\theta\rVert_1$ — that's ℓ₁ regularization (lasso). The regularizer was a prior all along.
Parameter space, live
The square is parameter space. Blue contours are the likelihood (data fit), teal contours are the prior (centered at the origin), and orange contours are their product, the posterior. The three marked points are the MLE (data's best fit), the MAP (posterior peak), and the origin. Move the controls and watch the MAP get tugged between the data and zero.
Why ℓ₁ gives sparsity and ℓ₂ does not
Look at the prior contours. The Gaussian prior draws smooth ellipses — round everywhere. When the likelihood ellipse presses against it, they meet at a generic point with both coordinates nonzero: ℓ₂ shrinks weights toward zero but rarely to zero.
The Laplace prior draws diamonds — with sharp corners sitting exactly on the axes. A tilted likelihood ellipse is very likely to first touch the diamond at a corner, and a corner has one coordinate equal to zero. That geometric fact — pointy ℓ₁ ball versus round ℓ₂ ball — is the entire reason lasso produces sparse models and ridge does not.