⚡ Logistic Regression with sklearn

These are Noah's notes on how to solve the no-show problem with scikit-learn, and on the two tools of the chapter that a real project cannot do without: regularization and k-fold cross-validation.

The interactive notebook includes:

  • A Pipeline that chains StandardScaler and LogisticRegression, so the test set never leaks into training.
  • Evaluation with the confusion matrix, the classification report and the ROC curve with its AUC.
  • A reproducible case of overfitting: few patients and many irrelevant variables.
  • L2 and L1 regularization, and how scikit-learn's C relates to the $\lambda$ of the book.
  • Choosing $\lambda$ with stratified 5-fold cross-validation over the book's logarithmic grid, and a final evaluation on an untouched test set.
  • Elastic Net with correlated variables: the two penalties together, how L1 splits a group of correlated columns and how stable its choice is across bootstrap samples.
  • Imbalanced classes: moving the threshold versus class_weight='balanced'.

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

Bibliography