How to judge a model honestly on data it has not seen, how to predict a category rather than a number, and how to turn a model’s probabilities into a decision once every kind of error has a price.
Slides¶
Present full screen Download the PDF
Click or tap the slide to move forward, its left edge to go back; the arrow keys work too.
Reading¶
Model Validation and Classification builds a churn model for Qahwa House’s loyalty-app members step by step: why “nobody leaves” is already 78.6% accurate, a logistic regression and its odds ratios, the confusion matrix and the ROC curve, a decision tree that scores 100% on its training data and 71% on new members, cross-validation, and the threshold that more than doubles the profit of a retention campaign.
Lab 7: Customer churn model with scikit-learn¶
Qahwa House can send a 10-SAR retention voucher to loyalty-app members who look likely to leave. Which members should get one, and how much is the campaign worth? You split the data, overfit a tree on purpose and fix it with cross-validation, fit a logistic regression, then write the campaign’s profit function and choose the threshold that maximises it, not the one that maximises accuracy.
Open the lab, then use its Open in Colab button.
Data: qahwa
_members _2025 .csv (6,000 members, one row each: activity over the 90 days to 30 September 2025, and whether they churned by the end of the year). The notebook downloads it by itself. Submit before the next lab session. The solutions are for checking your work afterwards.
Next week¶
Time-series forecasting: trend, seasonality, exponential smoothing and forecast errors, and a demand-forecast app in Streamlit.