Lesson deck

Linear models, loss functions and gradient descent flashcards

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

Loading your cards...

Back to the lesson11 cards in this deck

Read all 11 cards as a list
  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.