A Python portfolio project predicting whether e-commerce users will click on a promotional banner ad, using logistic regression for binary classification.
Originally published on Rose Data Scientist.
An e-commerce company's team wanted to predict, for visitors landing on a new page, whether they would click a promotional banner ad — based on user behavior and demographic features. The goal was a machine learning model to solve this classification problem.
Source: https://storage.googleapis.com/dqlab-dataset/pythonTutorial/ecommerce_banner_promo.csv
| Column | Description |
|---|---|
Daily Time Spent on Site |
Minutes the user spent on the site |
Age |
User's age (years) |
Area Income |
Average income in the user's area |
Daily Internet Usage |
Average minutes the user spends online per day |
Ad Topic Line |
Topic/content of the promo banner |
City |
City where the user accessed the site |
Male |
Whether the user is male |
Country |
Country where the user accessed the site |
Timestamp |
Time the user clicked the banner or left without clicking |
Clicked on Ad |
Target label — 1 = clicked, 0 = did not click |
The full analysis, in ctr_prediction.py, follows these steps:
- Data exploration —
head(),info(),describe(),shape - Correlation & label distribution —
corr(),groupby().size() - Visualization — histogram of user age distribution, seaborn pairplot of feature relationships
- Missing value check —
isnull().sum().sum() - Modeling — Logistic Regression, 80:20 train/test split, non-numeric columns (
Ad Topic Line,City,Country,Timestamp) dropped since the target and predictors must be numeric - Evaluation — training/testing accuracy, confusion matrix, classification report (precision, recall, F1-score)
| Metric | Score |
|---|---|
| Training Accuracy | 0.90 |
| Testing Accuracy | 0.90 |
Training and testing accuracy are nearly identical, meaning the model is neither overfitting (memorizing training data) nor underfitting (failing to learn patterns) — it generalizes well to new data.
Confusion Matrix:
| Predicted 0 | Predicted 1 | |
|---|---|---|
| Actual 0 | 85 | 4 |
| Actual 1 | 16 | 95 |
Classification Report:
| Class | Precision | Recall | F1-score |
|---|---|---|---|
| 0 | 0.84 | 0.96 | 0.89 |
| 1 | 0.96 | 0.86 | 0.90 |
| Macro avg | 0.90 | 0.91 | 0.90 |
| Weighted avg | 0.91 | 0.90 | 0.90 |
Interpretation:
- The model is very precise when predicting class 1 (96%) — few false alarms.
- It's more sensitive to class 0 (96% recall) than class 1 (86% recall) — it occasionally misses actual clicks (false negatives).
- Overall accuracy is 90% (180 out of 200 samples correctly classified), and macro/weighted averages are close, indicating the model isn't biased toward either class.
- There's room to improve recall for class 1 if catching every positive case (click) matters more than avoiding false positives.
See requirements.txt. Core libraries: pandas, matplotlib, seaborn, scikit-learn.
MIT