Join this channel to learn data science, artificial intelligence and machine learning with funny quizzes, interesting projects and amazing resources for free
For collaborations: @love_data
Post #3957
4.67K
✅ Data Science Project Series Part-2: Customer Churn Prediction
Project goal
Predict which customers will leave. Act before revenue drops.
Business value
• Retention costs less than acquisition
• Clear actions for sales and support
• High interview relevance
Dataset
Telco customer churn style dataset.
Target: Churn (Yes left, No stayed)
Key features
• tenure
• MonthlyCharges
• TotalCharges
• Contract
• PaymentMethod
• InternetService
Tech stack
• Python
• Pandas
• NumPy
• Matplotlib
• Seaborn
• Scikit-learn
Step 1. Import libraries
Step 2. Load data
Step 3. Basic checks
Step 4. Data cleaning
Convert TotalCharges to numeric.
Drop customer ID.
Step 5. Exploratory Data Analysis
Churn distribution.
Tenure vs churn.
Common insights:
• Month-to-month contracts churn more
• Low tenure users churn early
• High monthly charges increase churn
Step 6. Encode categorical variables
Step 7. Feature scaling
Step 8. Split data
Step 9. Build model
Step 10. Predictions
Step 11. Evaluation
Typical results:
• Accuracy around 78 to 83 percent
• ROC AUC around 0.84
• Recall for churn is key metric
Step 12. Business actions from model
• Target high-risk users
• Offer discounts to month-to-month users
• Push yearly contracts
• Improve onboarding for first 90 days
Resume bullet example:
• Built churn prediction model using Logistic Regression
• Identified contract type and tenure as top churn drivers
• Improved churn recall using class-aware split
Interview explanation flow:
• Revenue loss problem
• Why recall matters more than accuracy
• How features map to actions
Mini task for you:
• Train Random Forest
• Compare ROC AUC
• Tune threshold for higher recall
Double Tap ♥️ For Part-3
Project goal
Predict which customers will leave. Act before revenue drops.
Business value
• Retention costs less than acquisition
• Clear actions for sales and support
• High interview relevance
Dataset
Telco customer churn style dataset.
Target: Churn (Yes left, No stayed)
Key features
• tenure
• MonthlyCharges
• TotalCharges
• Contract
• PaymentMethod
• InternetService
Tech stack
• Python
• Pandas
• NumPy
• Matplotlib
• Seaborn
• Scikit-learn
Step 1. Import libraries
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import LabelEncoder, StandardScaler
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import classification_report, confusion_matrix, roc_auc_score
Step 2. Load data
df = pd.read_csv("customer_churn.csv")
df.head()Step 3. Basic checks
df.shape
df.info()
df.isnull().sum()
Step 4. Data cleaning
Convert TotalCharges to numeric.
df['TotalCharges'] = pd.to_numeric(df['TotalCharges'], errors='coerce')
df['TotalCharges'].fillna(df['TotalCharges'].median(), inplace=True)
Drop customer ID.
df.drop('customerID', axis=1, inplace=True)Step 5. Exploratory Data Analysis
Churn distribution.
sns.countplot(x='Churn', data=df)
plt.show()
Tenure vs churn.
sns.boxplot(x='Churn', y='tenure', data=df)
plt.show()
Common insights:
• Month-to-month contracts churn more
• Low tenure users churn early
• High monthly charges increase churn
Step 6. Encode categorical variables
le = LabelEncoder()
for col in df.select_dtypes(include='object').columns:
df[col] = le.fit_transform(df[col])
Step 7. Feature scaling
scaler = StandardScaler()
num_cols = ['tenure', 'MonthlyCharges', 'TotalCharges']
df[num_cols] = scaler.fit_transform(df[num_cols])
Step 8. Split data
X = df.drop('Churn', axis=1)
y = df['Churn']
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.3, random_state=42, stratify=y
)Step 9. Build model
model = LogisticRegression(max_iter=1000)
model.fit(X_train, y_train)
Step 10. Predictions
y_pred = model.predict(X_test)
y_prob = model.predict_proba(X_test)[:,1]
Step 11. Evaluation
confusion_matrix(y_test, y_pred)
print(classification_report(y_test, y_pred))
roc_auc_score(y_test, y_prob)
Typical results:
• Accuracy around 78 to 83 percent
• ROC AUC around 0.84
• Recall for churn is key metric
Step 12. Business actions from model
• Target high-risk users
• Offer discounts to month-to-month users
• Push yearly contracts
• Improve onboarding for first 90 days
Resume bullet example:
• Built churn prediction model using Logistic Regression
• Identified contract type and tenure as top churn drivers
• Improved churn recall using class-aware split
Interview explanation flow:
• Revenue loss problem
• Why recall matters more than accuracy
• How features map to actions
Mini task for you:
• Train Random Forest
• Compare ROC AUC
• Tune threshold for higher recall
Double Tap ♥️ For Part-3
- ❤ 17







