⚡ Logistic Regression from Scratch

These are Noah's notes on how to implement a logistic regression model from scratch, with NumPy and gradient descent. The notebook applies it to the problem of the chapter: predicting which Physiotherapy patients at Minermont will miss their appointment.

The interactive notebook includes:

  • Synthetic appointment data (age, days since the last visit, distance, time, first visit, previous no-shows) and a first exploration.
  • Stratified split into training and test sets, and feature scaling with the training statistics only.
  • The sigmoid function and the log loss, with examples of how it punishes confident mistakes.
  • Training with gradient descent and the evolution of the cost.
  • Evaluation with the confusion matrix, sensitivity, specificity, PPV and NPV, and the effect of the decision threshold.
  • Interpretation of the weights as odds ratios, and predictions for new patients.

Want to modify the code and experiment on your own?
Open the notebook in Google Colab

Bibliography