Free tutorials & notes in Hindi & English · Clean code examples 🧰 मुफ़्त PDF और फ़ोटो टूल्स →
🏆 Major Project – Churn Prediction  ·  दिन 56

दिन 56: Project 1: Business Problem और Data

⏱ 3 hours📶 Major project · Part 1 of 5🎯 100% self-study
दिन 56 / 60

✅ आज आप सीखेंगे

  • Churn telecom company को करोड़ों का नुकसान क्यों करता है, समझें
  • Business लक्ष्य को ML समस्या में बदलें
  • Data का audit करें और छिपे जाल पकड़ें
  • Baseline मापें: churn rate और जोखिम वाला revenue
  • Project charter और सफलता के metrics लिखें

🏢 असली दुनिया में

TeleOne, एक मध्यम आकार की Indian telecom और broadband company, साल में लगभग हर 10 में से 3 customers खो रही है। नया customer लाना एक को रोकने से लगभग पाँच गुना महँगा है। Head of Retention आपसे कहते हैं: “हर महीने मेरी team को उन customers की list दो जो जाने वाले हैं और बताओ क्यों – ताकि हम सही लोगों को सही offer के साथ call करें।” अगले पाँच दिनों में आप यही पूरा बनाएँगे, शुरू से आख़िर तक।

5-दिन का project plan

  1. 1Day 56 – business समस्या, data audit, baseline
  2. 2Day 57 – EDA, statistical tests, insights
  3. 3Day 58 – features, pipelines, model तुलना
  4. 4Day 59 – evaluation, threshold, ₹ impact, explanations
  5. 5Day 60 – deployment, risk list, report और presentation
वही workflow जो असली data teams अपनाती हैं

Step 1: business समझें

📉
Churn क्या है?Customer cancel करे या renew न करे। यहाँ: churn column = observation period में छोड़ गया।
💰
क्यों ज़रूरीहर खोया customer अपना monthly bill साथ ले जाता है – और बदले में नया लाना ~5× महँगा।
🎯
ActionRetention team high-risk customers को call करके discount, upgrade या yearly plan देती है।
📏
सफलताOffer budget के हर rupee पर अभी की random calling से ज़्यादा customers बचाना।
चार cards में business

Step 2: इसे ML समस्या बनाएँ

सवालइस project का जवाब
Target (y)churn = Yes / No → binary classification
Unitएक row = एक customer
Prediction का समयहर महीने की शुरुआत, उस दिन तक का data
OutputChurn की probability + हर customer के मुख्य कारण
कौन इस्तेमाल करेगाRetention call-centre team (≈ 600 calls/महीना क्षमता)
मुख्य metricROC-AUC + सबसे risky 20% customers में recall
Business metricNet ₹ बचत = बचाया revenue − offer cost
⚠️ सबसे पहले leakage check

हर column के लिए पूछें: “क्या यह customer के छोड़ने का फ़ैसला करने से पहले पता है?” “cancellation_reason” या “final_bill_date” जैसे columns leakage होंगे। हमारे data में सभी columns churn से पहले customer के बारे में हैं – पर हमेशा पूछें।

Step 3: data का audit

Python
import pandas as pd
raw = pd.read_csv("telecom_churn.csv")
print(raw.shape)
print(raw.dtypes.astype(str).to_dict())
print("Missing values:\n", raw.isna().sum()[raw.isna().sum() > 0])
print("internet_service values:", raw["internet_service"].value_counts(dropna=False).to_dict())
(3000, 13) {'customer_id': 'object', 'gender': 'object', 'senior_citizen': 'int64', 'tenure_months': 'int64', 'contract': 'object', 'internet_service': 'object', 'tech_support': 'object', 'payment_method': 'object', 'monthly_charges': 'float64', 'total_charges': 'float64', 'complaints': 'int64', 'data_usage_gb': 'float64', 'churn': 'object'} Missing values: internet_service 625 total_charges 25 dtype: int64 internet_service values: {'Fiber': 1327, 'DSL': 1048, nan: 625}
🕵️ छिपा हुआ जाल

625 customers की internet service missing दिखती है – पर वह missing नहीं है! उनकी value text “None” है (कोई internet plan नहीं), और pandas default में “None” को NaN बना देता है। इन्हें बिना सोचे drop या fill करने से 21% data बिगड़ जाता।

Python
import numpy as np
import pandas as pd

def load_churn(path="telecom_churn.csv"):
    # "None" means no internet plan – stop pandas from turning it into NaN
    df = pd.read_csv(path, keep_default_na=False, na_values=[""])
    df["total_charges"] = df["total_charges"].fillna(df["monthly_charges"] * df["tenure_months"])
    df["churned"] = (df["churn"] == "Yes").astype(int)
    return df

df = load_churn()
print(df["internet_service"].value_counts().to_dict())
print("Missing after load:", int(df.isna().sum().sum()))
print("Duplicates:", df["customer_id"].duplicated().sum())
check = (df["tech_support"] == "No internet") == (df["internet_service"] == "None")
print("tech_support consistent with internet_service:", bool(check.all()))
{'Fiber': 1327, 'DSL': 1048, 'None': 625} Missing after load: 0 Duplicates: 0 tech_support consistent with internet_service: True
Python
import numpy as np
import pandas as pd

def load_churn(path="telecom_churn.csv"):
    # "None" means no internet plan – stop pandas from turning it into NaN
    df = pd.read_csv(path, keep_default_na=False, na_values=[""])
    df["total_charges"] = df["total_charges"].fillna(df["monthly_charges"] * df["tenure_months"])
    df["churned"] = (df["churn"] == "Yes").astype(int)
    return df

df = load_churn()
rules = {"tenure 1–72 months": df["tenure_months"].between(1, 72).all(),
         "monthly charges > 0": (df["monthly_charges"] > 0).all(),
         "total ≈ monthly × tenure": (abs(df["total_charges"] - df["monthly_charges"] * df["tenure_months"]) / df["total_charges"] < 0.06).mean() > 0.95,
         "complaints ≥ 0": (df["complaints"] >= 0).all(),
         "churn only Yes/No": set(df["churn"]) == {"Yes", "No"}}
for rule, ok in rules.items():
    print(("✅" if ok else "❌"), rule)
✅ tenure 1–72 months ✅ monthly charges > 0 ✅ total ≈ monthly × tenure ✅ complaints ≥ 0 ✅ churn only Yes/No

Data dictionary

ColumnTypeमतलब
customer_ididUnique customer code
gender, senior_citizencategory / 0-1Demographics
tenure_monthsnumberTeleOne के साथ महीने (1–72)
contractcategoryMonthly / One year / Two year
internet_servicecategoryFiber / DSL / None
tech_supportcategoryYes / No / No internet
payment_methodcategoryUPI AutoPay / Credit Card / Bank Transfer / Cash
monthly_charges, total_charges₹मौजूदा bill और कुल ख़र्च
complaintscountपिछले 6 महीनों की शिकायतें
data_usage_gbnumberऔसत monthly data
churntargetYes = छोड़ गया

Step 4: baseline मापें

Python
import numpy as np
import pandas as pd

def load_churn(path="telecom_churn.csv"):
    # "None" means no internet plan – stop pandas from turning it into NaN
    df = pd.read_csv(path, keep_default_na=False, na_values=[""])
    df["total_charges"] = df["total_charges"].fillna(df["monthly_charges"] * df["tenure_months"])
    df["churned"] = (df["churn"] == "Yes").astype(int)
    return df

df = load_churn()
churners = df[df["churned"] == 1]
rate = df["churned"].mean()
monthly_lost = churners["monthly_charges"].sum()
print(f"Customers: {len(df):,} | churned: {len(churners):,} | churn rate: {rate:.1%}")
print(f"Monthly revenue walking out: ₹{monthly_lost:,.0f}  → per year ≈ ₹{monthly_lost * 12 / 1e5:.1f} lakh")
print(f"Average bill – churners ₹{churners['monthly_charges'].mean():.0f} vs stayers ₹{df.loc[df['churned'] == 0, 'monthly_charges'].mean():.0f}")
Customers: 3,000 | churned: 874 | churn rate: 29.1% Monthly revenue walking out: ₹663,644 → per year ≈ ₹79.6 lakh Average bill – churners ₹759 vs stayers ₹636
Python
import numpy as np
import pandas as pd

def load_churn(path="telecom_churn.csv"):
    # "None" means no internet plan – stop pandas from turning it into NaN
    df = pd.read_csv(path, keep_default_na=False, na_values=[""])
    df["total_charges"] = df["total_charges"].fillna(df["monthly_charges"] * df["tenure_months"])
    df["churned"] = (df["churn"] == "Yes").astype(int)
    return df

import matplotlib.pyplot as plt
df = load_churn()
fig, ax = plt.subplots(1, 2, figsize=(11, 3.8))
c = df["churn"].value_counts()
ax[0].pie(c, labels=[f"{k} ({v:,})" for k, v in c.items()], colors=["#94a3b8", "#dc2626"], autopct="%1.1f%%", startangle=90, wedgeprops=dict(width=0.45))
ax[0].set_title("29% of customers churned")
rev = df.groupby("churn")["monthly_charges"].sum() / 1e5
ax[1].bar(rev.index, rev.values, color=["#94a3b8", "#dc2626"]); ax[1].set_ylabel("₹ lakh per month")
ax[1].set_title("Monthly revenue: kept vs walked out")
for i, v in enumerate(rev.values): ax[1].text(i, v + 0.2, f"₹{v:.1f} L", ha="center")
plt.tight_layout(); plt.show()
Churned vs retained customers का donut और खोए monthly revenue का bar
एक slide जो बताती है project क्यों ज़रूरी है।

Step 5: business assumptions (retention team के साथ तय)

Python
assumptions = {
    "retention offer": "₹100 off per month for 6 months",
    "offer cost per accepted customer (₹)": 600,
    "call cost per customer contacted (₹)": 40,
    "share of true churners saved by a call + offer": 0.30,
    "share of non-churners who still take the offer": 0.50,
    "value of a saved customer (₹)": "monthly bill × 12 (one more year)",
    "call capacity per month": 600,
}
for k, v in assumptions.items():
    print(f"{k:48s} {v}")
saved_value = 759 * 12            # average churner bill ≈ ₹759 (Step 4)
print(f"\nOne saved churner ≈ ₹{saved_value:,} of revenue; cost of trying = ₹40 call (+ ₹600 if they accept)")
retention offer ₹100 off per month for 6 months offer cost per accepted customer (₹) 600 call cost per customer contacted (₹) 40 share of true churners saved by a call + offer 0.3 share of non-churners who still take the offer 0.5 value of a saved customer (₹) monthly bill × 12 (one more year) call capacity per month 600 One saved churner ≈ ₹9,108 of revenue; cost of trying = ₹40 call (+ ₹600 if they accept)
🧠 Assumptions लिखना क्यों?

Day 59 में हम model output को rupees में बदलेंगे। Modelling से पहले call, offer और save-rate की cost तय करना evaluation को ईमानदार रखता है और business बाद में बिना काम दोहराए कोई number बदल सकता है।

Step 6: project charter

Markdown – PROJECT_CHARTER.md
# TeleOne Churn Prediction – Project Charter
**Goal:** Reduce customer churn by targeting retention calls at customers most likely to leave.
**Users:** Retention team (600 calls / month).
**Deliverables:** (1) monthly risk list with top reasons, (2) Streamlit app for agents,
(3) model card and one-page report.
**Success metrics:** ROC-AUC ≥ 0.80 on unseen customers; ≥ 2× more churners reached
per call than random calling; positive net ₹ impact under agreed assumptions.
**Data:** 3,000 customers, 13 columns, snapshot at month start. No leakage columns.
**Risks:** small dataset; offer acceptance rate is an assumption → propose an A/B pilot.
**Timeline:** Day 56 problem & data · 57 EDA · 58 models · 59 evaluation · 60 deployment.

🏅 आज के Job Skills

✔ Business लक्ष्य को ML समस्या में बदलना✔ Data audit करके चुपचाप होने वाली parsing गलतियाँ पकड़ना✔ Baseline और जोखिम वाला revenue मापना✔ सफलता metrics के साथ project charter लिखना

Practice tasks

🏋️ Practice – ख़ुद करें

Task 1: 600 random customers को call करने से retention team को क्या मिलेगा? (कितने churners तक पहुँचेंगे, अनुमान)
Solution देखें
Python
import numpy as np
import pandas as pd

def load_churn(path="telecom_churn.csv"):
    # "None" means no internet plan – stop pandas from turning it into NaN
    df = pd.read_csv(path, keep_default_na=False, na_values=[""])
    df["total_charges"] = df["total_charges"].fillna(df["monthly_charges"] * df["tenure_months"])
    df["churned"] = (df["churn"] == "Yes").astype(int)
    return df

df = load_churn()
print(f"Random 600 calls reach ≈ {600 * df['churned'].mean():.0f} churners (the number our model must beat)")
Random 600 calls reach ≈ 175 churners (the number our model must beat)
Task 2: किस segment में सबसे ज़्यादा monthly revenue जोखिम में है: Fiber, DSL या None?
Solution देखें
Python
import numpy as np
import pandas as pd

def load_churn(path="telecom_churn.csv"):
    # "None" means no internet plan – stop pandas from turning it into NaN
    df = pd.read_csv(path, keep_default_na=False, na_values=[""])
    df["total_charges"] = df["total_charges"].fillna(df["monthly_charges"] * df["tenure_months"])
    df["churned"] = (df["churn"] == "Yes").astype(int)
    return df

df = load_churn()
print(df[df["churned"] == 1].groupby("internet_service")["monthly_charges"].sum().sort_values(ascending=False))
internet_service Fiber 487009.0 DSL 150615.0 None 26020.0 Name: monthly_charges, dtype: float64
Task 3: असली telecom company के churn dataset के लिए leakage के दो और उदाहरण लिखें।

Quick quiz

🧠 Quick Quiz – ख़ुद को जाँचें

1. 625 rows की internet service missing क्यों दिखी?
keep_default_na=False लें।
2. Prediction का समय क्यों ज़रूरी है?
Leakage रोकता है।
3. 600 customers को random call करने से लगभग…
600 × 29%।
4. इस project के लिए अच्छा business metric?
बचाया revenue minus offer cost।
5. Modelling से पहले assumptions क्यों तय करें?
लक्ष्य बीच में न बदलें।

Interview corner

💼 Interview Corner

Churn prediction समस्या को कैसे frame करेंगे?

Churn और observation window, prediction का समय और horizon, unit (customer), मान्य features (churn से पहले पता), action (सीमित क्षमता वाले retention offers), और statistical (AUC, recall@capacity) व business (net बचत) दोनों तरह के success metrics तय करें।

पहले कौन से data-quality checks चलाते हैं?

Shape और types, missing values (और वे कैसे encode हैं!), key पर duplicates, सही ranges, columns के बीच तालमेल (total ≈ monthly × tenure), target values और class balance।

सारांश

  • पहले business: churn revenue खाता है; action है targeted retention calls।
  • ML framing: binary target, prediction का समय, कोई leakage नहीं, क्षमता के हिसाब से metrics।
  • Audit में चुपचाप वाला “None” → NaN जाल मिला – load_churn() में ठीक।
  • Baseline: 29% churn; 600 random calls से ~175 churners तक पहुँच।
➡️ आगे

Day 57: EDA – कौन churn करता है और क्यों, patterns को statistically test करें और पहली insights लिखें।

अक्सर पूछे जाने वाले प्रश्न (FAQ)

क्या यह असली TeleOne data है?
TeleOne एक काल्पनिक company है और data इस course के लिए बना realistic simulated data है, ताकि आप project खुलकर explore और share कर सकें।
असली churn datasets कहाँ मिलेंगे?
Kaggle पर public IBM Telco Customer Churn dataset का ढाँचा मिलता-जुलता है – Day 60 के बाद इस project को उस पर दोहराएँ।
← Data Science (60 Days)
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

अगला topicदिन 57: Project 2: EDA और Insights आपकी प्रगति: 56 / 60 (93%) · Lesson 57 / 60 आगे बढ़ें →

यह lesson कैसा लगा?

आपकी राय से हम content और बेहतर बनाते हैं।

अपना review और सुझाव लिखें (वैकल्पिक)

Review approve होने के बाद आपका नाम और शहर इसके साथ public दिख सकते हैं। Email या phone न लिखें।

▶ CodingEasily on YouTube

Video से सीखें – आसान Hindi में

चुनी हुई video: RDBMS भाग 3 – Class XI Commerce IT

▶ Channel subscribe करें