Free tutorials & notes in Hindi & English · Clean code examples 🧰 मुफ़्त PDF और फ़ोटो टूल्स →
📐 Week 5 – Statistics और Probability  ·  दिन 26

दिन 26: Descriptive Statistics

⏱ 2 hours📶 Beginner → Intermediate🎯 100% self-study
दिन 26 / 60

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

  • केंद्र: mean, median, mode – और कब कौन धोखा देता है
  • फैलाव: range, variance, standard deviation, IQR
  • Percentiles और five-number summary
  • Skewness और coefficient of variation
  • अलग चीज़ों की तुलना के लिए z-scores

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

एक start-up freshers को लुभाने के लिए “average salary ₹16.7 lakh” बताता है। सच: दो founders ₹60 lakh कमाते हैं और ज़्यादातर team ₹6–8 lakh। कौन सी statistic पर भरोसा करें, यह जानना आपको धोखे से बचाता है – और आपके boss को धोखा देने से भी।

केंद्र के माप

Python
import numpy as np
import pandas as pd
salary = pd.Series([6, 6.5, 7, 7, 7.5, 8, 8, 8, 6, 60, 60], name="lakh")
print("Mean  :", round(salary.mean(), 2))
print("Median:", salary.median())
print("Mode  :", salary.mode().tolist())
print("Mean without founders:", round(salary[salary < 50].mean(), 2))
Mean : 16.73 Median: 7.5 Mode : [8.0] Mean without founders: 7.11
⚖️
Meanजोड़ ÷ गिनती। हर value लेता है, इसलिए outliers खींचते हैं।
🎯
MedianSort करने के बाद बीच की value। Outliers से नहीं डिगता – salary, price, income के लिए।
🔁
Modeसबसे बार-बार आने वाली value। Categories के लिए (सबसे लोकप्रिय size, शहर)।
सही “average” चुनें

फैलाव के माप

Python
import pandas as pd
a = pd.Series([30, 31, 29, 30, 32, 28, 30], name="Courier A (minutes)")
b = pd.Series([10, 55, 20, 45, 30, 15, 35], name="Courier B (minutes)")
for s in (a, b):
    print(f"{s.name}: mean={s.mean():.1f} range={s.max() - s.min()} var={s.var():.1f} sd={s.std():.1f}")
Courier A (minutes): mean=30.0 range=4 var=1.7 sd=1.3 Courier B (minutes): mean=30.0 range=45 var=266.7 sd=16.3
🛵 वही average, अलग अनुभव

दोनों couriers का average 30 मिनट है। Courier A भरोसेमंद है (SD ≈ 1.3), courier B lottery जैसा (SD ≈ 16)। Customers को अनिश्चितता से नफ़रत है – फैलाव उतना ही ज़रूरी है जितना average।

StatisticFormula (विचार)pandas
Rangemax − mins.max() - s.min()
Variancemean से दूरी के वर्गों का औसतs.var()
Standard deviation√variance – मूल units मेंs.std()
IQRQ3 − Q1 (बीच के 50%)s.quantile(.75) - s.quantile(.25)
CVSD ÷ mean × 100 (relative फैलाव)s.std() / s.mean() * 100
Python
import numpy as np
x = np.array([4, 8, 6, 5, 7])
mean = x.mean()
dev = x - mean
print("deviations:", dev, "| squared:", dev ** 2)
print("sample variance (÷ n-1):", (dev ** 2).sum() / (len(x) - 1), "=", x.var(ddof=1))
print("sample SD:", round(np.sqrt((dev ** 2).sum() / (len(x) - 1)), 3), "=", round(x.std(ddof=1), 3))
deviations: [-2. 2. 0. -1. 1.] | squared: [4. 4. 0. 1. 1.] sample variance (÷ n-1): 2.5 = 2.5 sample SD: 1.581 = 1.581
💡 n या n−1?

pandas .std() n−1 से भाग देता है (sample SD, data science में आम)। NumPy np.std() n से भाग देता है जब तक ddof=1 न दें। छोटा अंतर, पर interviews में पूछा जाता है!

Percentiles और five-number summary

Python
import pandas as pd
t = pd.read_csv("telecom_churn.csv")
bill = t["monthly_charges"]
print(bill.quantile([0, 0.25, 0.5, 0.75, 1]).round(0).to_dict())
print("90th percentile:", round(bill.quantile(0.9)), "→ top 10% pay more than this")
print("IQR:", round(bill.quantile(0.75) - bill.quantile(0.25)))
{0.0: 149.0, 0.25: 459.0, 0.5: 679.0, 0.75: 881.0, 1.0: 1408.0} 90th percentile: 1011 → top 10% pay more than this IQR: 422
Python
import pandas as pd
import matplotlib.pyplot as plt
t = pd.read_csv("telecom_churn.csv")
b = t["monthly_charges"]
fig, ax = plt.subplots(figsize=(9, 3.6))
ax.hist(b, bins=40, color="#c7d2fe", edgecolor="white")
for q, c, l in [(0.25, "#0891b2", "Q1"), (0.5, "#16a34a", "Median"), (0.75, "#0891b2", "Q3")]:
    ax.axvline(b.quantile(q), color=c, lw=2); ax.text(b.quantile(q), ax.get_ylim()[1] * 0.92, " " + l, color=c)
ax.axvline(b.mean(), color="#dc2626", ls="--", lw=2); ax.text(b.mean(), ax.get_ylim()[1] * 0.8, " Mean", color="#dc2626")
ax.set_title("Monthly bills: quartiles split customers into four equal groups"); ax.set_xlabel("₹ per month")
plt.show()
Q1, median, Q3 और mean lines के साथ monthly bills का histogram
25% customers Q1 के बाएँ, 50% median के बाएँ, 75% Q3 के बाएँ।

आकार: skewness और CV

Python
import pandas as pd
h = pd.read_csv("house_prices.csv")
s = pd.read_csv("sales_data.csv")
for name, col in [("House price", h["price_lakh"]), ("Unit price", s["unit_price"]), ("Customer age", s["customer_age"])]:
    print(f"{name:13s} mean={col.mean():9.1f} median={col.median():8.1f} skew={col.skew():5.2f} CV={col.std() / col.mean() * 100:5.1f}%")
House price mean= 56.8 median= 54.3 skew= 1.06 CV= 43.4% Unit price mean= 2499.2 median= 935.5 skew= 6.29 CV=259.9% Customer age mean= 31.9 median= 32.0 skew= 0.27 CV= 26.9%

z-scores: कोई value कितनी असामान्य है?

z = (value − mean) ÷ SD। यह बताता है कि value mean से कितने standard deviation दूर है। |z| > 3 बहुत असामान्य।

Python
import pandas as pd
st = pd.read_csv("students_performance.csv")
for subj in ["maths", "english"]:
    st[subj + "_z"] = ((st[subj] - st[subj].mean()) / st[subj].std()).round(2)
riya = st.iloc[7]
print(f"Student {riya.student_id}: maths {riya.maths} (z={riya.maths_z}), english {riya.english} (z={riya.english_z})")
print("Relative to classmates, the better subject is", "maths" if riya.maths_z > riya.english_z else "english")
print("Students with |z| > 2.5 in maths:", (st["maths_z"].abs() > 2.5).sum())
Student S1008: maths 61.0 (z=-0.32), english 68.0 (z=0.11) Relative to classmates, the better subject is english Students with |z| > 2.5 in maths: 5
Python
import pandas as pd
s = pd.read_csv("sales_data.csv")
s["revenue"] = s["quantity"] * s["unit_price"] * (1 - s["discount"])
s["z"] = (s["revenue"] - s["revenue"].mean()) / s["revenue"].std()
print("Orders with z > 3 (check for fraud or bulk buyers):", (s["z"] > 3).sum())
print(s.nlargest(3, "z")[["order_id", "product", "quantity", "revenue", "z"]].round(2).to_string(index=False))
Orders with z > 3 (check for fraud or bulk buyers): 35 order_id product quantity revenue z BK100824 Laptop 2 114432.0 13.88 BK101257 Laptop 2 112962.0 13.70 BK101612 Laptop 2 105231.5 12.73

असली example: salary report जो गुमराह न करे

Python
import pandas as pd
e = pd.read_csv("employees.csv")
d = pd.read_csv("departments.csv")
df = e.merge(d, on="dept_id", how="left").fillna({"dept_name": "Unassigned"})
rep = df.groupby("dept_name")["salary"].describe()[["count", "mean", "50%", "std", "min", "max"]]
rep["cv_%"] = (rep["std"] / rep["mean"] * 100).round(1)
print((rep / [1, 1000, 1000, 1000, 1000, 1000, 1]).round(1).rename(columns={"50%": "median"}))
print("(salaries in ₹ thousand)")
count mean median std min max cv_% dept_name Data Science 11.0 105.8 111.0 24.1 74.0 146.0 22.8 Finance 1.0 61.0 61.0 NaN 61.0 61.0 NaN HR 5.0 52.8 52.0 7.5 42.0 62.0 14.1 Marketing 1.0 79.0 79.0 NaN 79.0 79.0 NaN Sales 10.0 57.5 55.0 11.9 42.0 78.0 20.8 Unassigned 2.0 71.5 71.5 12.0 63.0 80.0 16.8 (salaries in ₹ thousand)

🏅 आज के Job Skills

✔ Mean vs median सही चुनना✔ SD और IQR से फैलाव मापना✔ Percentiles और quartiles पढ़ना✔ तुलना और anomalies के लिए z-scores

Practice tasks

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

Task 1: किस शहर में प्रति sqft house prices सबसे स्थिर हैं (सबसे कम CV)?
Solution देखें
Python
import pandas as pd
h = pd.read_csv("house_prices.csv")
h["ppsf"] = h["price_lakh"] * 1e5 / h["area_sqft"]
g = h.groupby("city")["ppsf"]
print((g.std() / g.mean() * 100).round(1).sort_values())
city Jaipur 12.5 Bengaluru 14.2 Hyderabad 15.1 Lucknow 15.4 Pune 15.7 Name: ppsf, dtype: float64
Task 2: Delhi के 2024 के daily AQI के 10th और 90th percentile निकालें।
Solution देखें
Python
import pandas as pd
w = pd.read_csv("delhi_weather.csv", parse_dates=["date"])
print(w[w["date"].dt.year == 2024]["aqi"].quantile([0.1, 0.9]).round(0))
0.1 76.0 0.9 296.0 Name: aqi, dtype: float64
Task 3: एक student ने mean 70, SD 4 वाले test में 78 और mean 80, SD 10 वाले test में 85 लाए। दूसरों की तुलना में किसमें बेहतर?
Solution देखें
Python
z1 = (78 - 70) / 4
z2 = (85 - 80) / 10
print("Test 1 z =", z1, "| Test 2 z =", z2, "→ better in", "Test 1" if z1 > z2 else "Test 2")
Test 1 z = 2.0 | Test 2 z = 0.5 → better in Test 1

Quick quiz

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

1. कुछ महलों वाली house prices के लिए सबसे अच्छा “average”?
Median extreme values को नज़रअंदाज़ करता है।
2. Standard deviation किस unit में होता है?
Variance squared है; SD उसका square root।
3. IQR किसे cover करता है?
Q1 से Q3 तक।
4. z = −2 का मतलब value…
z standard deviations गिनता है।
5. Mean > median आमतौर पर क्या बताता है?
लंबी right tail mean को ऊपर खींचती है।

Interview corner

💼 Interview Corner

Mean की जगह median कब report करेंगे?

जब data skewed हो या outliers हों – salaries, house prices, delivery times, session lengths। बेहतर है दोनों और एक फैलाव का माप (IQR या SD) बताएँ।

Manager को standard deviation समझाइए।

“औसतन एक delivery सामान्य 30 मिनट से लगभग X मिनट आगे-पीछे होती है।” छोटा SD = भरोसेमंद, बड़ा SD = अस्थिर।

सारांश

  • Symmetric data के लिए mean, skewed के लिए median, categories के लिए mode।
  • SD = mean से सामान्य दूरी; IQR = बीच के 50%।
  • Percentiles स्थिति बताते हैं; CV relative फैलाव की तुलना करता है।
  • z-scores अलग scales को एक पैमाने पर लाते हैं और outliers पकड़ते हैं।
➡️ आगे

Day 27: probability – अनिश्चितता की भाषा, simulations के साथ जो आप चला सकते हैं।

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

क्या describe() काफ़ी है?
यह count, mean, std, min, quartiles और max देता है – बढ़िया शुरुआत। पूरी तस्वीर के लिए median vs mean, skew और value counts जोड़ें।
“अच्छा” CV कितना है?
कोई universal नियम नहीं। मिलती-जुलती चीज़ों के CV की तुलना करें – जैसे delivery partners या शहर – कम मतलब ज़्यादा स्थिर।
← Data Science (60 Days)
🔗

Share this topic with a friend

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

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

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

अगला topicदिन 27: Data Science के लिए Probability आपकी प्रगति: 26 / 60 (43%) · Lesson 27 / 60 आगे बढ़ें →

यह lesson कैसा लगा?

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

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

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

▶ CodingEasily on YouTube

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

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

▶ Channel subscribe करें