Machine Learning
E-commerce
Real-time

ML in Ecommerce - Predicting Conversion

Real-time conversion prediction system for e-commerce with focus on recall and latency optimization

Student / ML Engineer
View Code
ML in Ecommerce - Predicting Conversion

Problem

KokoBananas, a cosmetics and health e-commerce company, was struggling with low conversion rates on their website. Too many visitors were browsing without making purchases, and the company needed to understand which customers were likely to convert in order to improve user experience and optimize their digital marketing efforts. The challenge was to build a machine learning model that could predict in real-time whether a customer session would result in a purchase, enabling the company to: - Identify high-value customers during their browsing session - Optimize user experience for potential converters - Make data-driven decisions about website improvements - Compete more effectively in the increasingly competitive digital cosmetics market

Solution

Developed a comprehensive machine learning pipeline to predict customer conversion using historical session data from the Online Shoppers Purchasing Intention Dataset. The solution focused on building a production-ready model with emphasis on: - **Real-time Performance**: Optimized for low latency since predictions needed to happen during active user sessions - **High Recall**: Prioritized capturing as many potential converters as possible - **Robust Preprocessing**: Handled missing values, outliers, and class imbalance effectively - **Model Comparison**: Evaluated multiple algorithms to find the optimal balance of accuracy and speed

Technical Implementation

**Comprehensive ML Pipeline**: - Exploratory Data Analysis to understand customer behavior patterns - Multiple preprocessing strategies for handling missing values (zero-filling, row dropping, KNN imputation) - Feature engineering including one-hot encoding for categorical variables and standard scaling for numerical features - Addressed severe class imbalance using three approaches: undersampling, oversampling, and SMOTE **Model Development**: - Tested 5 different algorithms: Logistic Regression, Decision Tree, Random Forest, AdaBoost, and K-Nearest Neighbors - Used StratifiedKFold cross-validation to handle imbalanced data properly - Implemented GridSearchCV for hyperparameter optimization across all models - Created custom evaluation metrics combining traditional ML metrics with latency measurements **Production Considerations**: - Measured median prediction latency (milliseconds per sample) for each model - Developed F1-style weighted score combining Recall/Precision with latency - Avoided double-counting minority class by setting class_weight=None when using resampled data - Comprehensive error analysis including false positive/negative pattern identification **Evaluation Framework**: - Tracked dataset profiles (sample count, minority class share) after each preprocessing step - Used confusion matrices and performance visualizations for model comparison - Created HTML displays of results for easy stakeholder communication

Key Learnings

**Technical Insights**: - Real-time ML systems require measuring latency from the beginning - performance optimization can't be an afterthought - Class imbalance handling is crucial but must be done carefully to avoid double-weighting - Feature preprocessing strategies can significantly impact both model performance and inference speed - GridSearchCV with proper cross-validation is essential for reliable model selection **Production ML Lessons**: - Business requirements (real-time prediction) should drive technical decisions from day one - Custom evaluation metrics that combine multiple business objectives (recall + latency) provide better model selection - Comprehensive error analysis helps identify model limitations and potential improvements - Documentation and visualization are crucial for stakeholder buy-in and model deployment **Collaboration & Tools**: - Successfully collaborated with AI tools (Claude) to accelerate development while maintaining code quality - Learned to write clear training strategies in markdown that could be translated into working code - Jupyter notebooks are excellent for ML experimentation but require careful output management for sharing **Business Understanding**: - E-commerce conversion prediction is highly dependent on user behavior patterns - Real-time prediction systems need to balance accuracy with speed constraints - Model interpretability becomes important when making business decisions based on predictions

Results & Impact

Built production-ready ML pipeline handling imbalanced e-commerce data
Optimized model selection for real-time latency requirements
Comprehensive evaluation of 5 different ML algorithms
Successfully handled missing values and class imbalance challenges
Created custom evaluation metrics combining business objectives
Delivered actionable insights for e-commerce conversion optimization
Tech Stack
Python
Scikit-learn
Pandas
NumPy
Jupyter Notebook
Imbalanced-learn
Matplotlib
Seaborn
Project Info
Date
April 2024
Role
Student / ML Engineer
Repository
View on GitHub