Data Sampling › Visual Examples {#visual-examples}

Michael BrenndoerferMay 16, 20255 min read
Machine Learning from ScratchAll chapters
Part 1 of 9Statistics 101
Chapter 5Data Sampling › Visual Examples {#visual-examples}
Reading section 6 of 10 · Visual Examples {#visual-examples} · 5 minSection 6 of 10 · 5 min

Book contents

Section 6 of 10 · 5 min read

Data Sampling › Visual Examples {#visual-examples}One section · Sections in this chapter6 / 10 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

To build intuition about sampling variability and how different sample sizes affect our estimates, let's simulate drawing samples from a known population and observe how sample means behave.

Example: Sampling Distribution of the Mean

This example demonstrates the sampling distribution concept by repeatedly drawing samples of different sizes from a population and showing how sample means vary around the true population mean. Larger samples produce estimates that cluster more tightly around the true value.

Out[2]:
Visualization
Histogram showing sampling distribution for n=10 sample size.
Sampling distribution for small samples (n=10). The histogram shows sample means from 1,000 different samples, each containing 10 observations drawn from a population with mean 50. The wide spread illustrates substantial sampling variability, with individual sample means ranging from approximately 46 to 54. The red dashed line marks the true population mean.
Histogram showing sampling distribution for n=100 sample size.
Sampling distribution for large samples (n=100). With ten times more observations per sample, the distribution of sample means becomes much narrower and more concentrated around the true population mean of 50. This demonstrates how larger samples reduce sampling error and produce more precise estimates.

Example: Comparing Sampling Methods

This visualization demonstrates how different sampling strategies can produce samples with varying degrees of representativeness. We'll compare simple random sampling with stratified sampling in a population containing distinct subgroups.

Out[3]:
Visualization
Scatter plot showing simple random sampling from stratified population.
Simple random sampling from a stratified population. Blue circles represent one subgroup (90% of population) and orange squares represent another (10% of population). The random sample (larger, darker markers) may by chance underrepresent or overrepresent the minority group, introducing sampling variability in group-specific estimates.
Scatter plot showing stratified sampling with proportional representation.
Stratified sampling ensuring proportional representation. By sampling from each subgroup separately, stratified sampling guarantees the sample mirrors the population's group structure. This reduces variability when estimating group-specific parameters and overall population characteristics that differ between groups.