Implement logistic regression with gradient descent in NumPy

8 steps · about 3 h 5 min · Intermediate

  1. Model probabilities with the logistic function (article, Wikipedia, 20 min)

    Sets out the model, the odds interpretation and maximum likelihood fitting.

  2. Picture how logistic regression fits data (video, StatQuest (YouTube), 10 min)

    A clear visual intuition before any algebra.

  3. Use cross-entropy as the loss (article, Wikipedia, 15 min)

    Connects log-loss to likelihood and shows why it suits probabilities.

  4. Derive the gradient from the lecture notes (reference, Stanford University, 40 min)

    Stanford CS229 notes derive the update rule for logistic regression step by step.

  5. Check gradients numerically and pick a step size (article, Stanford CS231n, 30 min)

    Shows numerical vs analytic gradients and the effect of learning rate.

  6. Vectorise the update with broadcasting (reference, NumPy, 15 min)

    Lets you compute predictions and gradients for all rows without loops.

  7. Code the training loop from scratch (tutorial, ML Glossary, 25 min)

    Complete Python implementation of sigmoid, cost, gradient and training.

  8. Extend to many classes with softmax (article, Dive into Deep Learning, 30 min)

    Generalises the same recipe to multiclass classification.