https://github.com/anhvu2201/churn_users_prediction_using_supervised_and_unsupervised_ml
Develop and train an supervised machine learning model to identify potential churn users. Additionally, segment these users into distinct groups using an unsupervised machine learning model to enable tailored marketing strategies.
https://github.com/anhvu2201/churn_users_prediction_using_supervised_and_unsupervised_ml
clustering-analysis supervised-machine-learning unsupervised-machine-learning
Last synced: about 1 month ago
JSON representation
Develop and train an supervised machine learning model to identify potential churn users. Additionally, segment these users into distinct groups using an unsupervised machine learning model to enable tailored marketing strategies.
- Host: GitHub
- URL: https://github.com/anhvu2201/churn_users_prediction_using_supervised_and_unsupervised_ml
- Owner: anhvu2201
- Created: 2025-01-04T05:02:56.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-02-09T06:00:11.000Z (over 1 year ago)
- Last Synced: 2025-11-28T19:44:20.736Z (7 months ago)
- Topics: clustering-analysis, supervised-machine-learning, unsupervised-machine-learning
- Language: Jupyter Notebook
- Homepage:
- Size: 2.23 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Churn Users Prediction using Supervised & Unsupervised Machine Learning
# I. Introduction
## 1. About Supervised Machine Learning:
- Supervised machine learning uses labeled data to train models, where input-output pairs are provided, enabling the model to predict outcomes for new, unseen data.
- Several application of unsupervised machine learning:
- Fraud detection in financial systems.
- Predictive maintenance in industries.
- Medical diagnosis based on patient data.
## 2. About Unsupervised Machine Learning:
- Unsupervised machine learning involves training models on data without labeled outcomes, aiming to identify patterns, structures, or groupings within the dataset.
- Several application of unsupervised machine learning:
- Customer segmentation for targeted marketing.
- Anomaly detection in fraud detection or cybersecurity.
- Data compression and visualization.
## 3. Project Purpose:
- Detect churned users and their likely patterns and behaviors using supervised machine learning.
- Segment the churn users into distinct groups through an unsupervised machine learning model.
- Provide insights about the differencies between the groups.
# II. Identify Churned Users by Supervised Machine Learning Model
## 1. Data & Libraries Preparation:

## 2. Exploratory Data Analysis - EDA:
### 2.1. Explore Data:



### 2.2. Check & Handle Missing and Duplicate Values:
#### 2.2.1. Handle Missing Values:


- Conlusion:
- Tenure: 264 values
- WarehouseToHome: 251 missing values
- HourSpendOnApp: 255 missing values
- OrderAmoutHikeformLastYear: 265 missing values
- CouponUsed: 256 missing values
- OrderCount: 258 missing values
- DaySinceLastOrder: 307 missing values
- Solution: Filling missing values with respectively median values.
#### 2.2.2 Handle Duplicate Values:


- Conclusion:
- Primal Key: CustomerID
- Duplicates in primal key: None
- Duplicates in sample: None
- Solution: No action needed.
### 2.3. Univariate Analysis:
#### 2.3.1. Correct Data Type:

#### 2.3.2. Numerical Data Analysis:
a. Select correct numerical data columns:

b. Checking value distribution using clustered column:

- Example of chart:

c. Checking value distribution using boxplot:

- Example of chart:

d. Result:

e. Solution:

- Solution: All outliers are replaced by their respective median values.
#### 2.3.3. Categorical Data Analysis:
a. Checking value distribution using clustered column:

- Example of chart:

b. Correcting data value:

### 2.4. Bivariate & Multivariate Analysis:
#### 2.4.1. Correlation Coefficient:

- Variables with positive correlation with churn users:
- Notable relationship: Complain.
- Variables with negative correlation with churn users:
- Medium Relationship: Tenure.
#### 2.4.2. Numerical Variables Relationship:


#### 2.4.3. Categorical Variables Relationship:







## 3. Feature Engineering:

- Select potetial features for the model.
## 4. Feature Transforming:

- Encode selected features for later progression.
## 5. Model Training:
### 5.1. Split Dataset:

### 5.2. Normalization:

### 5.3. Apply Model:

- Apply Random Forest to train the model.
## 6. Model Evaluation:


- Evaluate the model using Precision Score, F-1 Score & Model Fitting.
- The model is considerably accuracy as it achives 75&-95% on both train and test dataset in 3 tests.
## 7. Model Improvement:

- The model achives highest accuracy with the following super-parameters: {'class_weight': 'balanced', 'max_depth': None, 'n_estimators': 200}
# III. Segment Churned Users Into Groups Unsupervised Machine Learning Model:
## 1. Data & Libraries Preparation:

- Only churned users are selected as the unsupervised learning is aimed at this customer segment.
## 2. Exploratory Data Analysis - EDA:
- The EDA step is not required as it has been done on the previous Supervised Model part.
## 3. Feature Engineering & Feature Transforming:
### 3.1. Select Potential Features:

### 3.2. Encoding:

### 3.3. Normalization:

- As the results of normalization cannot be used in Dimension Reduction (PCA) due to low explained variance rate, the this step is only shown as an example.
### 3.4. Dimension Reduction:

- With high explained variance rate (97.9%), the result of PCA can be used later for unsupervised machine learning model.
## 4. Model Training - Apply K-Means Model:
### 4.1. Choosing K - Elbow Method:

### 4.2. Applying K-Means:

## 5. Model Evaluation:

### 5.1. Silhouette Score:

### 5.2. Distribution Of Clusters:

## 6. Analyzation:
- To get information about the clusters, a Supervised model is applied.
### 6.1. Select Potential Features:

### 6.2. Encoding:

### 6.3. Split Dataset into Train & Test Set:

### 6.4. Normalization:

### 6.5. Model Training using Random Forest:

### 6.6. Model Evaluation:

### 6.7. Feature Importance:

- Top features with greatest effect on deciding churned users, in order:
- CashbackAmount
- OrderCount
- PreferedOrderCat
### 6.8. Cluster Analyzation:
#### 6.8.1. Distribution of Cashback Amount Across Clusters:


#### 6.8.2. Distribution of Order Count Across Clusters:


#### 6.8.3. Distribution of Preferred Order Category Across Clusters:


# IV. Model Status
## 1. Supervised Machine Learning Model:
- Random Forest: High Precision, Fitting & Effective.
- Accuracy of Random Forest Fine-Tuned: 91.72%.
## 2. Unsupervised Machine Learning Model:
- K-means Model. K = 4
- Silhouetter Score: 0.46
# V. Insights
## 1. Common features of churned users:
- The users who have less that 15 months of tenure
- The users who complained in the last month
- The users who login by computer
- The users who stay in city tier 2 or 3
- The users who pay by Cash on Delivery or E-wallet
- The users who had preferred order category of Fashion or Mobile Phone
- The users with big satisfaction score
- The users who are currently single
## 2. Characteristics of churned users' groups:
- Group 1 (Cluster 0) - people with:
- Low average cashback amount in last month (145-155).
- Lower number of orders placed in last month (from 1-3 orders).
- Prefer mobile phone and laptop & accessory in last month.
- Group 2 (Cluster 1) - people with:
- High average cashback amount in last month (200 - 230).
- Higher number of orders placed last month (from 2-5 orders).
- Prefer laptop & accessory and fashion in the last month.
- Group 3 (Cluster 2) - people with:
- Low average cashback amount in last month (120 - 130).
- Lower number of orders placed last month (from 1-2 orders).
- Prefer mobile phone in the last month.
- Group 4 (Cluster 3) - people with:
- Medium average cashback amount in last month (165 - 190).
- Higher number of orders placed last month (from 2-4 orders).
- Prefer laptop & accessory, mobile phone and fashion in the last month.
# VI. Recommendation:
- Several factors of users that cannot be changed or improved: MaritalStatus, Tenure. The company is not able to do anything regarding these factors.
- On the other hand, there are other factors can be improved by the company to reduce the number of churn users:
- Complain: The business need to improve the quality of product and customer service, solve the problems as they rise so the customers will be satisfied and may not complain.
- LoginDevice: The business need to test and fix any bugs or technical problems that affect the experience of customers login using computer
- CityTier: The business need to invest more on marketing in city tier 1, reduce investment on city tier 2 and 3.
- PaymentMethod: The business need to find and resolve any inconvenience in using Cash on Delivery and E-wallet to make purchase, in order to improve the purchasing experience of users in these payment methods.
- Preferred Category: The business need to improve the quality of product in Fashion and Mobile Phone segments.
- Satisfaction Score: On this factor, it is needed to check if the score is in an ascending or descending order. In case the score is sorted in ascending order, this is a strange phenomenon that should be monitoring further.