Data Science ยท Chapter 21 of 43
Sampling & Bias
A SAMPLE is a subset used to estimate something about the whole POPULATION.
Biased samples give biased conclusions no matter how much data you collect (e.g. only surveying happy users).
Example 1 (python)
import numpy as np
sample = np.random.choice(population, size=1000, replace=False)Simple random sample.
Example 2 (python)
# Stratified sampling: sample within each group
# to preserve subgroup proportionsBetter for imbalanced groups.
Key points
- Sample = subset of population.
- Random sampling reduces bias.
- Stratified sampling preserves subgroup ratios.
- Selection bias โ small sample.
๐ก Note: Survivorship bias is everywhere โ dead startups don't answer surveys about why they failed.
