A machine learning project that predicts customer purchase amounts using demographic, geographic, and product-related features.
The project uses Linear Regression to model the relationship between customer and product attributes and purchase amount, followed by evaluation on unseen test data.
Understanding customer purchasing behaviour is an important problem in retail analytics. Transactional datasets contain valuable information about customers, products, demographics, and purchasing patterns that can be used to build predictive models.
The goal of this project is to develop a regression-based machine learning pipeline that can:
- Predict the purchase amount for a customer-product combination
- Analyse how customer and product attributes relate to purchasing behaviour
- Evaluate prediction performance using standard regression metrics
- Generate purchase predictions for unseen customer records
Input: Customer and product attributes
Output: Predicted Purchase amount
The project uses a retail purchase dataset containing 550,068 transactions and 12 attributes.
| Feature | Description |
|---|---|
User_ID |
Unique customer identifier |
Product_ID |
Unique product identifier |
Gender |
Customer gender |
Age |
Customer age group |
Occupation |
Customer occupation category |
City_Category |
Category of the customer's city |
Stay_In_Current_City_Years |
Number of years living in the current city |
Marital_Status |
Customer marital status |
Product_Category_1 |
Primary product category |
Product_Category_2 |
Secondary product category |
Product_Category_3 |
Tertiary product category |
Purchase |
Purchase amount - prediction target |
The observed purchase amounts range from 12 to 23,961, with an average purchase amount of approximately 9,264.
The project follows a typical supervised machine learning workflow:
Raw Dataset
│
▼
Data Exploration
│
▼
Data Preprocessing
│
├── Missing Value Handling
├── Categorical Encoding
├── Feature Transformation
└── Feature Scaling
│
▼
Train / Test Split
│
▼
Linear Regression
│
▼
Model Evaluation
│
├── MAE
├── RMSE
└── R² Score
│
▼
Purchase Prediction
Linear Regression is used as the primary regression model to predict purchase amounts from customer and product attributes.
The modelling pipeline includes:
- Categorical feature encoding
- Numerical feature transformation
- Feature scaling
- Linear Regression
- Model evaluation on unseen test data
The model is implemented using scikit-learn.
The model was evaluated using three standard regression metrics:
| Metric | Result |
|---|---|
| MAE | 2,208.91 |
| RMSE | 2,946.09 |
| R² Score | 0.6546 |
The model achieved an R² score of 0.6546 on the test set, indicating that approximately 65.46% of the variation in purchase amounts is explained by the features used in the model.
| Dataset | R² Score |
|---|---|
| Training | 0.6619 |
| Testing | 0.6546 |
The relatively small difference between the training and testing R² scores indicates that the model performs similarly on both datasets.
The following visualization compares the actual purchase amounts with the predicted purchase amounts generated by the Linear Regression model.
| Technology | Purpose |
|---|---|
| Python | Core programming language |
| Pandas | Data manipulation and analysis |
| NumPy | Numerical computation |
| Matplotlib | Data visualization |
| Seaborn | Exploratory data visualization |
| Scikit-learn | Machine learning and model evaluation |
| Jupyter Notebook | Experimentation and analysis |
git clone https://github.com/simran2104/purchase-prediction-engine.git
cd purchase-prediction-enginepip install -r requirements.txtOpen:
Purchase-Prediction.ipynb
Execute the notebook cells to:
- Explore the dataset
- Perform data preprocessing
- Train the regression model
- Evaluate model performance
- Visualize predictions
- Generate purchase predictions