Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Online Shoppers Purchasing Intention — Marketing Predictive Analytics

Predicting whether an e-commerce session will generate revenue, and identifying the behavioural signals that drive online purchases, using five classification models.

MBA Marketing Analytics · Predictive Analytics Assignment


Project Overview

E-commerce platforms attract large volumes of traffic, yet only a small fraction of sessions end in a purchase. In this dataset, only 15.5% of the 12,330 sessions convert. Spending marketing budget uniformly across all visitors is inefficient, because most were never going to buy. This project builds and compares classification models that predict the purchase outcome of a session (Revenue), so that retargeting spend, personalisation, and on-site interventions can be concentrated on high-intent visitors.

The workflow, coding conventions, and visualisation style follow an existing Digital Marketing Campaign reference notebook, extended to the five algorithms required by the assignment.

Business Problem

Which website sessions are likely to end in a purchase, so that marketing spend and on-site interventions can be focused on high-intent visitors?

  • Target variable: Revenue (Boolean — purchase completed or not)
  • Task: Binary classification under class imbalance (≈ 5.5 : 1)
  • Primary metric: F1 Score (with ROC-AUC), rather than raw accuracy

Dataset

  • Source: Online Shoppers Purchasing Intention dataset
  • Rows: 12,330 sessions · Columns: 18 (17 predictors + target)
  • Feature groups: page-visit counts, time-on-page durations, Google Analytics metrics (BounceRates, ExitRates, PageValues), temporal/context (Month, SpecialDay, Weekend), technical/environment codes (OperatingSystems, Browser, Region, TrafficType), and visitor profile (VisitorType).

Methodology

  1. Import libraries
  2. Load dataset
  3. Exploratory data analysis & data-quality assessment (nulls, duplicates, dtypes)
  4. Target-variable distribution & bivariate analysis
  5. Data preprocessing — duplicate removal, Boolean-to-integer conversion
  6. Categorical encoding (LabelEncoder)
  7. Outlier detection (Z-score; retained)
  8. Correlation analysis
  9. Stratified train/test split (80/20) + StandardScaler
  10. Build and evaluate five classifiers
  11. Model comparison leaderboard + cross-validation
  12. Best-model deep dive (confusion matrix, ROC)
  13. Feature importance & business insights

Models Compared

Logistic Regression · Decision Tree · Random Forest · Gradient Boosting · XGBoost.

Class imbalance is handled with class_weight="balanced" (LR, DT, RF) and scale_pos_weight (XGBoost).

Results

Models are ranked by F1 Score, the most reliable single metric under class imbalance.

Rank Model Accuracy Precision Recall F1 Score ROC-AUC
1 XGBoost 0.880 0.585 0.804 0.677 0.929
2 Gradient Boosting 0.899 0.705 0.607 0.653 0.928
3 Logistic Regression 0.873 0.569 0.764 0.653 0.898
4 Random Forest 0.899 0.734 0.555 0.632 0.926
5 Decision Tree 0.855 0.525 0.788 0.630 0.894

Best model — XGBoost: highest F1 (0.677) and ROC-AUC (0.929), with the strongest recall among the top models, meaning it captures the most actual purchasers. PageValues is by far the most important predictor across all tree ensembles, followed by ProductRelated_Duration, ExitRates, and Month.

Repository Structure

Marketing-Predictive-Analytics/
│
├── data/                 # Raw dataset (online_shoppers_intention.csv)
├── notebooks/            # Main analysis notebook (executed, with outputs)
├── src/                  # Reusable pipeline module (model_pipeline.py)
├── images/               # Generated figures (EDA, ROC, confusion matrices, etc.)
├── report/               # Written project report
├── presentation/         # MBA viva presentation
├── README.md
├── requirements.txt
├── LICENSE
└── .gitignore

Installation

# Clone the repository
git clone https://github.com/<your-username>/Marketing-Predictive-Analytics.git
cd Marketing-Predictive-Analytics

# (Optional) create a virtual environment
python -m venv venv
source venv/bin/activate        # Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

Usage

Run the full analysis notebook:

jupyter notebook notebooks/online_shoppers_intention_analysis.ipynb

Reproduce the leaderboard from the command line:

python src/model_pipeline.py --data data/online_shoppers_intention.csv

Key Business Recommendations

  • Score sessions in real time and trigger interventions (discount pop-ups, free-shipping banners, cart reminders) for high-propensity visitors.
  • Prioritise returning visitors and seasonal peaks (November and the holiday run-up show the highest purchase rates) when allocating retargeting budget.
  • Improve product-page UX to reduce exit and bounce rates, which are among the top negative drivers of conversion.
  • Favour behavioural targeting over demographic/technical targeting — engagement signals dominate; Browser, OS, and Region rank low in importance.

Limitations & Future Scope

  • Technical fields (OperatingSystems, Browser, Region, TrafficType) are anonymised integer codes, limiting their interpretability.
  • LabelEncoder imposes an arbitrary order on nominal categories; one-hot encoding could be tested for the linear and distance-based models.
  • Future work: hyperparameter tuning (GridSearchCV), SMOTE oversampling, probability calibration, engineered interaction features, and deployment as a real-time scoring API.

License

Released under the MIT License. See LICENSE for details.

About

Predicting online shopper purchase intention with 5 classification models. MBA Marketing Analytics project comparing Logistic Regression, Decision Tree, Random Forest, Gradient Boosting & XGBoost on 12,330 e-commerce sessions.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages