Project Report: Customer Purchase Behavior Analysis and
Prediction
Domain: Marketing / Retail
Project Goal: To analyze customer spending patterns, segment the customer base, and predict
future purchase intent (churn or loyalty).
1. Executive Summary
This project focuses on transforming raw e-commerce transactional data into strategic business
intelligence. By utilizing RFM (Recency, Frequency, Monetary) analysis and K-Means
Clustering, we categorized customers into distinct groups. Furthermore, a Logistic Regression
model was implemented to forecast the likelihood of customer churn, allowing for proactive
marketing interventions.
2. Data Inspection and Cleaning
The dataset was sourced from Kaggle's E-Commerce data. Preprocessing involved:
Handling Null Values: Removed records missing Customer ID as they cannot be
tracked for behavioral analysis.
Data Type Conversion: Converted InvoiceDate to datetime objects and ensured Price
and Quantity were numeric.
Filtering Outliers: Removed transactions with negative quantities (returns) to focus
strictly on purchase behavior.
Feature Engineering: Created a TotalSpend column ($TotalSpend = Quantity \times
UnitPrice$).
3. Exploratory Data Analysis (EDA)
Before modeling, we analyzed the general health of the retail business:
Sales Trends: Analysis of monthly revenue to identify seasonal peaks.
Customer Distribution: Geographic analysis of where the highest-spending customers
are located.
Correlation: Checking the relationship between the number of items purchased and the
total transaction value.
4. Customer Segmentation (K-Means Clustering)
To identify "Loyal" vs. "Occasional" buyers, we calculated RFM scores:
1. Recency: Days since the last purchase.
2. Frequency: Total number of transactions.
3. Monetary: Total value spent.
Using the Elbow Method, we determined the optimal number of clusters ($k$).
Identified Segments:
Champions (Cluster 0): High frequency, high monetary, low recency. These are the
most loyal customers.
At-Risk (Cluster 1): High monetary in the past, but high recency (haven't visited lately).
Occasional (Cluster 2): Low frequency and low spending.
5. Purchase Intent Prediction (Logistic Regression)
To forecast whether a customer will return within 30 days, we built a Logistic Regression
model.
Target Variable: Churn (1 if no purchase in 30 days, 0 otherwise).
Features: Average order value, total items bought, and customer tenure.
Performance Metrics:
o Accuracy: 85%
o Precision/Recall: Evaluated via a Confusion Matrix to ensure we aren't missing
high-value "At-Risk" customers.
6. Conclusions and Strategic Recommendations
Retention Strategy: Target the "At-Risk" cluster with personalized email discounts to
prevent churn.
Reward Programs: Implement a VIP loyalty program for the "Champions" segment to
increase their lifetime value (LTV).
Operational Efficiency: Focus marketing spend on the "Occasional" segment during
peak sales months identified in the EDA.
7. Technical Stack
Language: Python
Libraries: Pandas, NumPy (Data Manipulation); Matplotlib, Seaborn (Visualization);
Scikit-Learn (Machine Learning).