Module deck

ML foundations flashcards

Reviewing needs JavaScript. You can read every card in the list below.

Loading your cards...

Back to the module21 cards in this deck

Read all 21 cards as a list

The learning problem: generalization, bias-variance and regularization

  1. Front
    What is empirical risk, and what is it a proxy for?
    Back
    The average loss on the training set. It stands in for expected risk, the average loss on unseen data from the same source, which we cannot measure directly. Learning works only if the first tracks the second.
  2. Front
    Parameter versus hyperparameter?
    Back
    Parameters (weights) are learned from training data by the optimizer. Hyperparameters (learning rate, tree depth, lambda) are set by you and chosen with validation data.
  3. Front
    What is the job of each split: train, validation, test?
    Back
    Train fits the parameters. Validation chooses hyperparameters and models. Test is used once at the end for an unbiased estimate. Train learns, validation chooses, test judges.
  4. Front
    Name three data leaks and the fix for each.
    Back
    Scaler or imputer fitted before splitting: fit inside the training fold (a Pipeline). Rows of one entity on both sides: group k-fold. Random split on time-ordered data: forward-chaining split.
  5. Front
    Write the squared-error decomposition and say what each term means.
    Back
    Expected error = bias squared + variance + irreducible noise. Bias is systematic error from a too-simple model, variance is sensitivity to the training sample, noise is label noise no model can remove.
  6. Front
    Train error 2%, validation error 25%. Diagnosis and fixes?
    Back
    High variance (overfitting). After ruling out leakage: more data, regularization, a simpler model, early stopping, augmentation, or bagging. A bigger model makes it worse.
  7. Front
    What do learning curves show, and when does more data not help?
    Back
    Train and validation error against training-set size. Both plateau high and close together means bias: more data will not help, add capacity or features. A large gap that narrows with data means variance: more data helps.
  8. Front
    Why does L1 give exact zeros but L2 does not?
    Back
    The L1 gradient has constant size, so it can push a small weight all the way to zero (the solution is a soft threshold). The L2 gradient shrinks in proportion to the weight, so it approaches zero but does not arrive. Geometrically the L1 diamond has corners on the axes.
  9. Front
    What does raising lambda do to training error and to validation error?
    Back
    Training error never falls (it rises or stays flat), because the penalty makes the fit to the training data worse. Validation error usually falls first as variance drops, then rises once the model underfits. Choose lambda at the validation minimum.
  10. Front
    Why standardize features before an L1 or L2 penalty?
    Back
    The penalty adds up weight sizes, and a weight's size depends on the feature's units. Without scaling, the penalty treats metres and millimetres differently. Fit the scaler on training data only.

Linear models, loss functions and gradient descent

  1. Front
    Derive the gradient of the log loss for logistic regression.
    Back
    With p = sigmoid(z) and z = w.x + b: dl/dp = -y/p + (1-y)/(1-p) and dp/dz = p(1-p). The p(1-p) cancels the denominators, leaving dl/dz = p - y, so the gradient with respect to w is (p - y) x and with respect to b is p - y.
  2. Front
    Why use log loss, not squared error, with a sigmoid?
    Back
    Log loss is the Bernoulli negative log-likelihood and is convex in the weights. Squared error on a sigmoid keeps a p(1-p) factor in its gradient, which is near 0 when the model is confidently wrong, so learning stalls, and the loss is not convex.
  3. Front
    What happens to unpenalised logistic regression on perfectly separable data?
    Back
    The loss approaches 0 as the weights grow, so there is no finite minimiser and the weights never stop growing (slowly). An L2 or L1 penalty, or early stopping, keeps them finite.
  4. Front
    Write the normal equation and say when to avoid it.
    Back
    w = (X'X)^-1 X'y, from setting the gradient to zero, meaning the residual is orthogonal to every column of X. Avoid it when d is large (cost about n d^2 plus d^3), when data must stream, when there is no closed form, and when columns are collinear so X'X is nearly singular. Ridge fixes the last case.
  5. Front
    Collinear features: what breaks and what does not?
    Back
    Individual coefficients become unstable, with large variance and possibly wrong signs, because the data cannot separate the features' effects. Predictions usually stay fine. Fix with ridge, or drop or merge the correlated features.
  6. Front
    Which constant minimises squared error, and which minimises absolute error?
    Back
    The mean minimises squared error and the median minimises absolute error. For [1, 2, 3, 4, 100] the mean is 22 and the median is 3, which is why squared error is outlier-sensitive.
  7. Front
    Describe Huber loss and when to use it.
    Back
    Quadratic for small residuals, linear for large ones, so outliers get a lesser weight without being ignored. Use it when outliers are likely and you do not want to chase them, after checking why they exist.
  8. Front
    Hinge loss versus log loss: what is each for?
    Back
    Hinge is max(0, 1 - m) with margin m = y f(x): it is exactly 0 beyond a margin of 1, so only points near or past the boundary matter, and it gives no probability. Log loss, log(1 + e^-m), keeps a shrinking penalty on every point and gives probabilities you can threshold by cost.
  9. Front
    What does the learning rate do, and what do diverging, oscillating and crawling losses tell you?
    Back
    It scales the step: w = w - lr * gradient. On a quadratic with curvature h it converges only when lr is below 2/h. Loss rising or NaN means too high (or unscaled inputs, or log of 0). Bouncing at the same level means right at the limit. A barely moving loss means too low.
  10. Front
    What do momentum and Adam each add to gradient descent?
    Back
    Momentum keeps a leaky sum of past gradients: agreeing directions speed up and zigzags cancel. Adam keeps running averages of the gradient and its square, divides one by the root of the other with bias correction, so every parameter gets its own step size (first step about the learning rate). Both have hyperparameters to tune, and neither always wins.
  11. Front
    Why standardise features before gradient descent, and what is the catch?
    Back
    Different scales make the loss a thin canyon (high condition number), so the stable learning rate is set by the steepest direction and the rest crawls. In the lesson's experiment, steps fell from about 97,000 on raw features to 3 on standardised ones. Fit the scaler on training data only.