DeepLLM Quiz
Machine Learning

The lasso and generalised weight decay: penalties that switch weights off

10 questions on the L1 and L2 penalties, the lasso, sparse solutions, constraint regions with corners, and the link between penalising and constraining.

  • 10 questions
  • Stopwatch
  • Instant feedback

Shown publicly with your score. Don’t use your full real name.

Sample questions

Play now ↑

Answers stay hidden. Start the quiz to play them.

  1. Sample 1

    Two weights have unpenalised best values of 3 and 0.2. A strong penalty is applied. Which outcome is typical for the lasso compared with the quadratic penalty?

    • Both penalties set the small weight to exactly zero
    • Neither penalty changes the weights
    • The lasso can set the small weight to exactly zero, while the quadratic penalty only shrinks both

How it works

  • One question per screen. An answer is final once sent.
  • You see right away whether you were right, with a short explanation.
  • The stopwatch runs: on equal scores, the faster player ranks first.
  • Only your best attempt counts, so replaying is never risky.

About this quiz

A spam filter looks at two thousand word counts for each message. Perhaps fifty of those words matter, and the other nineteen hundred and fifty contribute noise. A model that gives every word a small non-zero weight is hard to interpret, expensive to store and prone to chasing chance patterns. A model that sets most weights to exactly zero is lean and readable: the words it keeps are the ones that matter. A penalty on the sizes of the weights can achieve either result, depending on how the size is measured. That is the subject of this quiz.

The standard penalty adds up the squares of the weights. A close relative adds up their absolute values instead, and is known by the memorable name lasso. The difference sounds small, but it changes the behaviour of the solution in a striking way. With the squared penalty, weights shrink towards zero but stay non-zero. With the absolute-value penalty, once the strength is large enough, some weights reach exactly zero and stay there. The quiz asks why, with the help of a picture in which the best weights are found by letting the contours of the error expand until they touch a constraint region.

You will also see how the penalised form of the problem and the constrained form are two descriptions of the same thing, linked through the idea of a Lagrange multiplier, and how a whole family of penalties can be generated by varying the power applied to each weight. The questions are scenarios such as a model with many features, an increase in penalty strength, or a comparison of two solutions for the same data.

Some misconceptions come up often. People expect the quadratic penalty to produce sparse models, which it does not. They assume the lasso always deletes the same features whatever the strength, when the number removed grows as the penalty is turned up. And some imagine that once a penalty is in place nothing needs to be chosen, whereas the strength has become the new thing to tune. The practical value of sparsity goes beyond tidiness. A model that depends on fifty inputs can be audited by a person, can be deployed on small devices, and often generalises better when many of the original inputs are irrelevant. Scientists use the same idea to ask which of many measured quantities really influence an outcome. At the same time, sparsity is not free: when several inputs carry nearly the same information, an absolute-value penalty may keep one arbitrarily and drop the others, so the surviving list should be read as one good explanation, not the only one.

The quiz suits learners with some experience of regularisation, and practitioners interested in feature selection. It asks for no calculation. There are 10 questions, each with an explanation, and it takes about four minutes.

Questions and answers

›How long does the quiz take?

About 3 to 4 minutes for 10 questions, at roughly 20 seconds each. Each answer is followed by an explanation that includes the geometric reasoning where it applies.

›Do I need to know about weight decay first?

It helps, since the lasso is best understood as a variation on it. The quiz on weight decay and effective parameters is a natural preparation, though the questions here recall the essential points.

›What is generalised weight decay?

It is a family of penalties formed by summing each weight's absolute value raised to a chosen power. A power of two gives the usual quadratic penalty. A power of one gives the lasso. Other powers give penalties whose contours are rounder or pointier, which changes how strongly they favour weights being exactly zero.

›What is the lasso?

It is the penalty made from the sum of the absolute values of the weights, and the name comes from the statistics literature. When the error is a quadratic function of the weights, a sufficiently strong lasso penalty drives some weights exactly to zero. The model becomes sparse, with the corresponding features or basis functions playing no part in its predictions. Weaker penalties shrink the weights without removing any, so the strength decides how sparse the result is.

›Why does the lasso produce zeros when the quadratic penalty does not?

Think of a constraint on the total size of the weights. For the absolute-value measure, the allowed region is a diamond with its corners on the axes, where one weight is zero. The expanding contours of the error tend to touch the diamond at such a corner. For the squared measure the region is a circle, with no corners, so both weights end up non-zero.

›What does a sparse model give you?

A sparse model uses only a subset of its inputs or basis functions, so it is cheaper to store and to evaluate, and it is easier to inspect, since the surviving features are the ones the data support. It also acts as a form of feature selection. The cost is that the choice of strength matters more, since too much sparsity discards useful features.

›How are penalising and constraining related?

Minimising the error plus a penalty gives the same solutions as minimising the error subject to a limit on the penalty's size, for a suitably matched limit. The two views are connected by Lagrange multipliers, and each has its uses: the penalised form is easy to optimise, and the constrained form gives a clear geometric picture.

›Does regularisation settle the question of model complexity?

It lets complex models be trained on modest data without severe overfitting, by limiting effective complexity. But the question of how complex the model should be does not vanish. It turns into the question of what penalty strength to use, which is typically settled by trying several values on held-out data.

More quizzes