Classify and Evaluate: Logistic Regression to Cross-Validation
Who it is for
What you will achieve
Prerequisites
Curriculum
- Step 1: Logistic Regression and the Sigmoid: Score, Squash, Decide
How logistic regression turns a price into the probability of a car: why a straight line fails, Euler's number e, the sigmoid, the 0.5 threshold, the decision boundary and log loss, on eight vehicles.
- Step 2: Logistic Regression in scikit-learn: predict, predict_proba and Softmax
Logistic regression as the last step of a scikit-learn pipeline on Rain in Australia: test accuracy, max_iter and ConvergenceWarning, predict vs predict_proba, then three Iris classes and softmax worked by hand.
- Step 3: Why Accuracy Lies: The Confusion Matrix, Baselines and Type I/II Errors
On 20,000 card payments with 1% fraud, a model that never looks scores 99% accuracy and catches nothing. The confusion matrix shows what accuracy hides: 21 frauds caught, 29 missed.
- Step 4: Precision, Recall and F1 Score: Two Questions and One Balance
Precision asks whether the model's yes is right; recall asks whether it found them all. Worked by hand and with scikit-learn on a fraud model with 99.4% accuracy and only 0.42 recall.
- Step 5: ROC Curve, AUC and Choosing a Classification Threshold
The 0.5 cut is only a default. On 1% fraud data: slide the threshold, draw the ROC and precision-recall curves, read AUC 0.877, pick the best-F1 cut on validation data, then open the test part once.
- Step 6: Handling Imbalanced Data: class_weight, SMOTE and the Resampling Leak
With 150 frauds among 15,000 training payments, a model learns to ignore fraud. Compare class_weight, random oversampling and SMOTE, see why full balance overshoots, pick a gentle SMOTE on validation data and avoid the resample-before-split leak.
- Step 7: Cross-Validation: KFold, StratifiedKFold, cross_val_score and cross_validate
The same model on five different splits scores F1 from 0.52 to 0.63. Cross-validation replaces one lucky number with a mean and a spread: KFold vs StratifiedKFold, cross_val_score, cross_validate on four models, then one honest test.