The primary objective of this project is to build a supervised machine learning classification model capable of predicting whether a customer will respond positively to a marketing campaign. By analyzing customer demographics, purchasing behavior, and historical interaction with previous campaigns, the model helps businesses optimize their marketing strategies. Instead of spending resources targeting all customers, the business can accurately identify the segment most likely to accept the offer, thereby increasing conversion rates and maximizing return on investment (ROI).
Dataset URL: Customer Personality Analysis on Kaggle
The dataset contains detailed information regarding the company's customer base, structured into various attributes:
- Response: 1 if the customer accepted the offer in the last campaign, 0 otherwise.
People (Demographics & History)
- ID: Customer's unique identifier.
- Year_Birth: Customer's birth year.
- Education: Customer's highest education level.
- Marital_Status: Customer's marital status.
- Income: Customer's yearly household income.
- Kidhome: Number of children in the customer's household.
- Teenhome: Number of teenagers in the customer's household.
- Dt_Customer: Date of the customer's enrollment with the company.
- Recency: Number of days since the customer's last purchase.
- Complain: 1 if the customer complained in the last 2 years, 0 otherwise.
Products (Spending Habits over the last 2 years)
- MntWines: Amount spent on wine.
- MntFruits: Amount spent on fruits.
- MntMeatProducts: Amount spent on meat products.
- MntFishProducts: Amount spent on fish products.
- MntSweetProducts: Amount spent on sweets.
- MntGoldProds: Amount spent on gold products.
Promotion (Campaign History & Deal Usage)
- NumDealsPurchases: Number of purchases made with a discount.
- AcceptedCmp1: 1 if the customer accepted the offer in the 1st campaign, 0 otherwise.
- AcceptedCmp2: 1 if the customer accepted the offer in the 2nd campaign, 0 otherwise.
- AcceptedCmp3: 1 if the customer accepted the offer in the 3rd campaign, 0 otherwise.
- AcceptedCmp4: 1 if the customer accepted the offer in the 4th campaign, 0 otherwise.
- AcceptedCmp5: 1 if the customer accepted the offer in the 5th campaign, 0 otherwise.
Place (Channels of Purchase)
- NumWebPurchases: Number of purchases made through the company's website.
- NumCatalogPurchases: Number of purchases made using a catalog.
- NumStorePurchases: Number of purchases made directly in stores.
- NumWebVisitsMonth: Number of visits to the company's website in the last month.
(Note: Features like Z_CostContact and Z_Revenue have constant values across the dataset and are typically removed during preprocessing).
To ensure the model receives high-quality data, the following techniques were utilized for data preprocessing:
- Handling Missing Values: Missing values (primarily found in the
Incomecolumn) were imputed using the median to avoid skewing the distribution with extreme values. - Date/Time Formatting: The
Dt_Customerfeature was converted to a standarddatetimeformat. - Feature Engineering: * Derived an
Agefeature by subtractingYear_Birthfrom the current data year.- Created an
Enrollment_Duration(or Tenure) feature to measure customer loyalty based onDt_Customer. - Aggregated spending columns to create a
Total_Spendfeature. - Combined
KidhomeandTeenhometo create aTotal_Dependentsfeature.
- Created an
- Dropping Irrelevant Features: Removed identifier columns like
IDand constant variables likeZ_CostContactandZ_Revenueas they hold no predictive power. - Categorical Encoding: Applied One-Hot Encoding and Label Encoding to convert categorical text data (e.g.,
Education,Marital_Status) into numeric formats.Marital_Statusanomalies (like 'YOLO' or 'Absurd') were merged into broader logical categories (e.g., 'Single'). - Feature Scaling: Standardized numerical variables using
StandardScalerto bring all features to a similar scale, optimizing algorithm convergence. - Class Imbalance Treatment: Applied techniques like SMOTE (Synthetic Minority Over-sampling Technique) to address class imbalances in the target
Responsevariable, preventing the model from becoming biased toward the majority class.
Various classification algorithms were trained and tested to find the best performing model for predicting campaign response:
- Logistic Regression: Serving as a strong, interpretable baseline model.
- Decision Tree Classifier: To capture non-linear relationships and segment boundaries.
- Random Forest Classifier: An ensemble method used to reduce overfitting and improve predictive accuracy.
- Gradient Boosting Classifiers (XGBoost / LightGBM): Advanced ensemble techniques that sequentially correct errors from previous decision trees, highly effective on tabular data.
- Support Vector Machines (SVM): Used to find the optimal hyper-plane separating customers who accept offers from those who do not.
To robustly assess model performance beyond simple accuracy, the following metrics were evaluated:
- Accuracy: The overall percentage of correctly predicted responses.
- Precision: The proportion of predicted positive responses that were actually positive (minimizing false positives to save marketing costs).
- Recall (Sensitivity): The proportion of actual positive responses correctly identified by the model (minimizing false negatives to avoid missing out on potential buyers).
- F1-Score: The harmonic mean of Precision and Recall, providing a balanced metric—especially useful due to target class imbalances.
- ROC-AUC (Receiver Operating Characteristic - Area Under Curve): Measures the model's ability to distinguish between the two classes (responders vs. non-responders) across various threshold levels.
- Confusion Matrix: Utilized to visualize the breakdown of True Positives, True Negatives, False Positives, and False Negatives.
Backend:
- Django (Python Web Framework)
- SQLite (Default Database)
Frontend:
- HTML / CSS / JavaScript
- Bootstrap 5 (via
django-crispy-formsandcrispy-bootstrap5)
Machine Learning & Data Processing:
- XGBoost
- Scikit-Learn
- Pandas
- Joblib
Follow these steps to set up and run the system locally:
-
Clone the repository:
git clone <repository-url> cd Customer-Personality-Analysis
-
Create a virtual environment:
python -m venv venv # On Windows: venv\Scripts\activate # On macOS/Linux: source venv/bin/activate
-
Install dependencies:
pip install -r requirements.txt
-
Apply database migrations:
python manage.py migrate
-
Run the development server:
python manage.py runserver
-
Access the application: Open your web browser and navigate to
http://127.0.0.1:8000/
This project is licensed under the MIT License - see the LICENSE file for details.







