Ravindra Bagale · Data Scienceसर्व coursesया course चे lessonsशोधाEnglish

Data Science · मराठी आवृत्ती

21.6 Sampling intuition (हलकी)

By Ravindra Bagale

या course चे सर्व chapters (py + ch)

हे का शिकायचं?

पूर्ण data नेहमी मिळत नाही. Sample वरून बोलताना n, काळ आणि city स्पष्ट सांगा.

हे काय आहे?

Sample = population चा तुकडा. छोटा n = जास्त अनिश्चितता. Bias = काही गट जास्त/कमी दिसणे.

कसं करायचं?

Step 1. Sample size n लिहा.

Step 2. कालावधी आणि filter सांगा.

Step 3. एक weekend ≠ पूर्ण महिना.

Step 4. “या sample मध्ये” असे लिहा.

उदाहरणं: copy करा आणि चालवा

उदाहरण A — Biased vs fair peek.

import pandas as pd
import numpy as np

rng = np.random.default_rng(0)
days = np.arange(1, 31)
# fictional daily order counts for Solapur
counts = rng.integers(40, 70, size=30)
counts[14:22] += 50  # Diwali window bump
daily = pd.DataFrame({"day": days, "orders": counts})

biased = daily.loc[daily["day"].between(15, 22), "orders"].mean()
fair = daily["orders"].mean()
print("Diwali-only mean orders/day", round(biased, 1))
print("Full October mean", round(fair, 1))

Biased peek overstates how “busy” Solapur always is.

उदाहरण B — Reproducible sample.

big = pd.DataFrame({
    "order_id": [f"AMN-{i}" for i in range(1000)],
    "city": rng.choice(
        ["Pune", "Nashik", "Nagpur", "Kolhapur"], size=1000
    ),
    "amount": rng.integers(50, 400, size=1000),
})
sample = big.sample(n=100, random_state=42)
print(sample["city"].value_counts())
print("sample mean ₹", round(sample["amount"].mean(), 1),
      "full mean ₹", round(big["amount"].mean(), 1))

random_state=42 lets Ruhi and Amir get the same 100 rows tomorrow.

उदाहरण C — What not to do.

Do not open the “interesting” cancelled orders only, compute a cancel rate, and present it as the city cancel rate. That is selection bias — same family of mistake as deleting outliers silently.