This project focuses on predicting whether a customer will purchase a product based on features like Gender, Age, and Estimated Salary. The machine learning model used in this project is Logistic Regression, which is suitable for binary classification problems.
The complete workflow of this project includes:
- Data loading
- Data exploration
- Data preprocessing
- Data visualization
- Model building
- Prediction and evaluation
The main objective of this project is to build a classification model that can predict customer purchase behavior using customer demographic and salary-related information.
The dataset used in this project is Social Network Ads.csv.
- User ID – Unique identifier for each customer
- Gender – Male or Female
- Age – Age of the customer
- EstimatedSalary – Estimated annual salary of the customer
- Purchased – Target variable (0 = Not Purchased, 1 = Purchased)
User IDwas removed because it does not contribute to prediction.Purchasedis the dependent variable.
- Python
- Pandas
- NumPy
- Matplotlib
- Seaborn
- Scikit-learn
- Jupyter Notebook
In this project, basic data exploration and visual analysis were performed to better understand the dataset.
- Checking dataset shape
- Viewing top rows of the dataset
- Checking null values
- Checking duplicate values
- Understanding data types
- Statistical summary of numerical columns
- Visualizing gender distribution
- Visualizing purchase count by gender
- The dataset contains 400 rows and 5 columns.
- No missing values were found.
- No duplicate values were found.
- Gender distribution is fairly balanced.
- Purchase behavior varies across customers and can be influenced by age and salary.
This project includes the following visualizations:
- Gender Count Plot
- Purchase Count by Gender
- Confusion Matrix Heatmap
These visualizations help in understanding the distribution of data and the final model performance.
The following preprocessing steps were performed before model training:
- Removed the
User IDcolumn - Converted categorical gender values into numerical format using encoding
- Selected important input features
- Split the dataset into training and testing sets
The model used in this project is:
Logistic Regression is a supervised machine learning algorithm used for binary classification. Here, it is used to predict whether a customer will purchase a product or not.
The project evaluates the model using:
- Accuracy Score
- Confusion Matrix
- Model Accuracy: 82.5%
- True Negatives = 61
- False Positives = 12
- False Negatives = 9
- True Positives = 38
This shows that the model performs well in classifying customer purchase behavior.
Customer-Purchase-Classification-using-Logistic-Regression.ipynb– Main notebookSocial_Network_Ads.csv– Dataset fileGender-Countplot.jpg– Gender distribution plotPurchase-Countplot.jpg– Purchase count by gender plotModel-Result.jpg– Confusion matrix result
- Clone this repository.
- Open the project folder.
- Install required libraries if not already installed:
pip install pandas numpy matplotlib seaborn scikit-learn- Open the Jupyter Notebook.
- Run all cells step by step.
This project demonstrates how Logistic Regression can be applied to solve a real-world binary classification problem. Using customer details like age, gender, and estimated salary, the model predicts whether a customer is likely to purchase a product.
It is a simple and effective beginner-friendly machine learning project that covers the full pipeline from data analysis to model evaluation.
This project can be improved further by:
- Applying feature scaling
- Trying other classification algorithms
- Using cross-validation
- Evaluating with precision, recall, and F1-score
- Building a small deployment app using Flask or Streamlit
Through this project, the following concepts were practiced:
- Binary classification
- Logistic Regression
- Data preprocessing
- Exploratory Data Analysis
- Data visualization
- Model evaluation
Adiratna Kamble
If you like this project, feel free to star the repository and connect with me on GitHub.