Predictive Purchase Outcome Model
An end-to-end machine learning project to predict whether a customer will keep, exchange, or refund a purchase, complete with a live simulator.

The Business Challenge
For any e-commerce business, returns and exchanges are a major operational cost and can indicate customer dissatisfaction. Understanding the factors that lead to these outcomes is crucial for improving product offerings, marketing strategies, and the overall customer experience.
The mission of this project was to build a predictive model that can forecast the outcome of a purchase at the point of transaction. By predicting whether an item is likely to be kept, exchanged, or refunded, the business can proactively address potential issues, manage inventory more effectively, and tailor post-purchase communication.
My Development Process
Feature Engineering & Preprocessing
I began with a large transactional dataset and engineered a rich set of features. This included creating customer segments (e.g., 'loyal_buyer'), calculating historical return/exchange rates per customer, and determining return patterns for specific product categories and shopping channels.
Model Training & Hyperparameter Tuning
After balancing the dataset to handle class imbalance, I trained several models. The final model, an **XGBoost Classifier**, was selected for its high performance. I used GridSearchCV to fine-tune its hyperparameters, optimizing for the best possible accuracy and F1-score.
API Development
I built a robust REST API using **FastAPI** to serve the trained model. The API includes endpoints for making single predictions in real-time and for running bulk simulations on generated data, demonstrating the model's practical application.
Interactive Frontend Simulator
To showcase the project, I developed a user-friendly web interface with HTML, Tailwind CSS, and JavaScript. This simulator connects to the FastAPI backend, allowing users to input purchase details and receive an instant prediction, complete with a performance dashboard.
Key Information
- Type: E-Commerce
- Tools: Python, FastAPI
- Model: XGBoost
Technology Stack
- Python
- FastAPI
- Scikit-learn & Pandas
- XGBoost
- HTML, JS, Chart.js
Key Features
- Business Focus: Reduces return rates by identifying at-risk purchases.
- Business Focus: Improves customer satisfaction through proactive engagement.
- Technical: Deploys a tuned XGBoost model via a high-performance FastAPI backend.
- Technical: Full-stack implementation from data analysis to a live, interactive simulator.
Model Performance & Key Insights
The final XGBoost model achieved a strong overall accuracy of 70%. More importantly, it showed excellent performance in identifying products that would be kept, which is crucial for business operations.
High "Keep" Prediction Accuracy
The model correctly identifies items that customers will keep with 90% precision, helping to confirm satisfactory purchases.
Customer Segmentation is Key
The analysis revealed that customer segments like 'loyal_buyer' and 'frequent_buyer' were strong predictors of purchase outcomes.
Actionable Business Insights
By predicting exchanges and refunds, the business can optimize inventory and explore targeted interventions to improve customer satisfaction.