Topic 43 of

Standard Deviation and Variance — Measuring Data Spread

Mean tells you where data is centered, but standard deviation tells you how SPREAD OUT it is. Two datasets can have the same mean but wildly different reliability.

📚Beginner
⏱️9 min
10 quizzes
📊

What is Data Spread (Dispersion)?

Mean, median, and mode tell you where data is centered (typical value). But they don't tell you how spread out (varied) the data is.

Why Spread Matters

Example — Two Swiggy Delivery Partners:

Partner A: Delivers in 28, 29, 30, 31, 32 minutes (5 deliveries)

  • Mean: 30 minutes
  • Spread: Very consistent (28-32 min range, only 4 min difference)

Partner B: Delivers in 10, 20, 30, 40, 50 minutes (5 deliveries)

  • Mean: 30 minutes
  • Spread: Highly inconsistent (10-50 min range, 40 min difference)

Both have same mean (30 min), but Partner A is RELIABLE (low spread), Partner B is UNPREDICTABLE (high spread).

Business Decision: Assign high-priority orders to Partner A (consistent), investigate Partner B (why so variable?).


Measures of Spread

| Measure | Description | Sensitivity to Outliers | When to Use | |---------|-------------|------------------------|-------------| | Range | Max - Min | Extremely sensitive (uses only 2 values) | Quick check, small datasets | | IQR | Q3 - Q1 (middle 50% spread) | Resistant (ignores top/bottom 25%) | Outlier-resistant spread | | Variance | Average squared deviation from mean | Sensitive | Mathematical calculations (rarely reported alone) | | Standard Deviation | Square root of variance | Sensitive | Most common (same units as data) |

Standard deviation (SD) is the most widely used measure of spread — it's the "average distance" of data points from the mean.

Think of it this way...

Imagine two archers shooting arrows at a target. Both average bulls-eye (same mean), but Archer A's arrows cluster tightly around center (low SD = consistent), while Archer B's arrows scatter across the target (high SD = inconsistent). SD measures "tightness" of clustering around the mean.

🔢

Variance and Standard Deviation: Definitions and Formulas

Variance (σ² or s²)

Definition: Average of squared deviations from mean.

Why "squared"? Raw deviations sum to zero (negative and positive cancel out). Squaring makes all deviations positive.

Formula (Population Variance):

σ² = Σ(xᵢ - μ)² / N Where: - xᵢ = each data point - μ = population mean - N = population size - Σ = sum of all

Formula (Sample Variance) — most common in practice:

s² = Σ(xᵢ - x̄)² / (n - 1) Where: - x̄ = sample mean - n = sample size - (n-1) = Bessel's correction (makes estimate unbiased)

Units: Variance is in squared units (e.g., if data is in minutes, variance is in "minutes²"). This is hard to interpret, so we use standard deviation.


Standard Deviation (σ or s)

Definition: Square root of variance.

Formula:

SD = √Variance Population SD: σ = √(σ²) Sample SD: s = √(s²)

Units: Same as original data (e.g., if data is in minutes, SD is in minutes). This makes it interpretable.


Step-by-Step Calculation Example

Data: Flipkart delivery times (5 orders): 22, 25, 28, 30, 35 minutes

Step 1: Calculate Mean

Mean (x̄) = (22 + 25 + 28 + 30 + 35) / 5 = 140 / 5 = 28 minutes

Step 2: Calculate Deviations from Mean

22 - 28 = -6 25 - 28 = -3 28 - 28 = 0 30 - 28 = 2 35 - 28 = 7

Step 3: Square the Deviations

(-6)² = 36 (-3)² = 9 (0)² = 0 (2)² = 4 (7)² = 49

Step 4: Calculate Variance

s² = (36 + 9 + 0 + 4 + 49) / (5 - 1) = 98 / 4 = 24.5 minutes²

Step 5: Calculate Standard Deviation

s = √24.5 = 4.95 minutes

Interpretation: On average, delivery times deviate from the mean (28 min) by about 5 minutes. Most deliveries are between 23-33 minutes (mean ± 1SD).


Python/Pandas Calculation

code.pyPython
import pandas as pd
import numpy as np

data = pd.Series([22, 25, 28, 30, 35])

# Mean
mean = data.mean()  # 28.0

# Variance (sample variance, uses n-1)
variance = data.var()  # 24.5

# Standard Deviation
std_dev = data.std()  # 4.95

# Or using NumPy
variance_np = np.var(data, ddof=1)  # ddof=1 for sample variance
std_dev_np = np.std(data, ddof=1)   # ddof=1 for sample SD

print(f"Mean: {mean}, Variance: {variance}, SD: {std_dev:.2f}")
Info

Always use sample variance/SD (n-1 denominator) when working with sample data (most real-world cases). Population variance (n denominator) is only for complete populations (rare). Pandas .var() and .std() use n-1 by default (correct for samples).

⚠️ CheckpointQuiz error: Missing or invalid options array

📈

Interpreting Standard Deviation: The 68-95-99.7 Rule

For normally distributed data (bell curve), standard deviation follows a predictable pattern.

The 68-95-99.7 Rule (Empirical Rule)

If data is normally distributed:

68% of data ├─────────────────────┤ ┌──────────────────┐ │ │ │ ╱╲ │ │ ╱ ╲ │ 95% of data │ ╱ ╲ │ │ ╱ ╲ │ ─────┼───╱────────╲─────┼───── 99.7% of data │ ╱ ╲ │ │ ╱ ╲ │ ─────┴──────────────────┴───── μ-3σ μ-2σ μ μ+2σ μ+3σ - 68% of data within 1 SD of mean (μ ± σ) - 95% of data within 2 SD of mean (μ ± 2σ) - 99.7% of data within 3 SD of mean (μ ± 3σ)

Real Example: Zomato Order Preparation Time

Restaurant data (1,000 orders):

  • Mean preparation time: 20 minutes
  • Standard deviation: 4 minutes
  • Distribution: Approximately normal (bell curve)

Applying 68-95-99.7 Rule:

1 SD from mean (68% of orders):

20 ± 4 = [16, 24] minutes → 68% of orders prepared in 16-24 minutes → 34% take 16-20 min, 34% take 20-24 min

2 SD from mean (95% of orders):

20 ± 8 = [12, 28] minutes → 95% of orders prepared in 12-28 minutes → Only 5% fall outside this range (outliers)

3 SD from mean (99.7% of orders):

20 ± 12 = [8, 32] minutes → 99.7% of orders prepared in 8-32 minutes → Only 0.3% are outliers (investigate these)

Using SD for Quality Control

Setting Thresholds:

  • Alert: Order takes >28 min (>2 SD, unusual, top 2.5%)
  • Critical Alert: Order takes >32 min (>3 SD, very unusual, top 0.15%)

Why this works: If system is consistent (low SD), outliers are obvious. High SD means noisy data (hard to detect issues).


When Data is NOT Normal

68-95-99.7 rule assumes normal distribution. For skewed data (income, order values), this rule breaks down.

Better approach for skewed data: Use percentiles instead.

  • Median (50th percentile)
  • 25th and 75th percentiles (IQR)
  • 90th, 95th, 99th percentiles (outliers)

Example — E-commerce Order Values (Right-Skewed):

Mean: ₹2,500 SD: ₹3,000 Distribution: Right-skewed (most orders ₹500-₹1,500, few ₹20K+) Mean - 1SD = ₹2,500 - ₹3,000 = -₹500 (impossible!) → SD doesn't work for skewed data

Solution: Report percentiles instead:

P50 (median): ₹1,000 P75: ₹1,800 P95: ₹5,500 P99: ₹15,000

This gives clear picture without assuming normality.

🏢

Real-World Applications of Standard Deviation

SD is used in quality control, risk analysis, performance monitoring, and anomaly detection.

Application 1: Quality Control (Manufacturing)

Context: Factory produces bolts with target diameter 10mm.

Data (sample of 100 bolts):

  • Mean diameter: 10.02 mm
  • Standard deviation: 0.05 mm

Quality Threshold: Bolts must be 10 ± 0.15 mm (tolerance range).

Analysis:

Tolerance: [9.85, 10.15] mm 3 SD range: 10.02 ± 3(0.05) = [9.87, 10.17] mm → 99.7% of bolts fall within [9.87, 10.17] → Only 0.3% exceed tolerance (acceptable defect rate)

Action: Process is in control (low SD, within tolerance). No intervention needed.

If SD increased to 0.10 mm:

3 SD range: 10.02 ± 3(0.10) = [9.72, 10.32] mm → Some bolts exceed tolerance [9.85, 10.15] → Defect rate increases (machine needs calibration)

Takeaway: Low SD = high quality (consistency). Monitor SD over time to detect process degradation.


Application 2: Risk Analysis (Stock Market)

Context: Comparing two stocks for investment.

Stock A (stable large-cap):

  • Average monthly return: 8%
  • Standard deviation: 3%
  • Low risk (consistent returns)

Stock B (volatile small-cap):

  • Average monthly return: 8%
  • Standard deviation: 15%
  • High risk (unpredictable returns)

Analysis:

Stock A: 8% ± 3% → Most months: 5% to 11% return (predictable) Stock B: 8% ± 15% → Most months: -7% to 23% return (wild swings)

Investment Decision:

  • Risk-averse investor: Choose Stock A (low SD, stable)
  • Risk-tolerant investor: Choose Stock B (high SD, potential for big gains)

Sharpe Ratio (risk-adjusted return):

Sharpe Ratio = (Return - Risk-Free Rate) / SD Stock A: (8% - 2%) / 3% = 2.0 Stock B: (8% - 2%) / 15% = 0.4 → Stock A has better risk-adjusted return (higher Sharpe ratio)

Takeaway: SD measures risk. Higher SD = higher volatility = higher risk.


Application 3: Performance Monitoring (Website Load Time)

Context: Monitor website performance across 10,000 page loads.

Data:

  • Mean load time: 1.8 seconds
  • Standard deviation: 0.4 seconds
  • Distribution: Approximately normal

SLA (Service Level Agreement): 95% of pages must load in 2.5 seconds.

Analysis:

95% of data within 2 SD: 1.8 ± 2(0.4) = [1.0, 2.6] seconds → 95% of pages load in 1.0-2.6 seconds → Slightly above SLA target (2.5s)

Action: Optimize to reduce mean OR SD:

  • Reduce mean (1.8s → 1.5s): Faster average load
  • Reduce SD (0.4s → 0.3s): More consistent performance

After Optimization:

Mean: 1.5s, SD: 0.3s 95% range: 1.5 ± 2(0.3) = [0.9, 2.1] seconds → Now meeting SLA (95% < 2.5s, actually 95% < 2.1s)

Takeaway: Low SD = consistent user experience. High SD = some users suffer (outliers).


Application 4: Anomaly Detection (Fraud/Error Detection)

Context: Detect unusual credit card transactions (potential fraud).

Customer's Transaction History (30 days):

  • Mean transaction: ₹1,200
  • Standard deviation: ₹400
  • Distribution: Normal

New Transaction: ₹8,500

Anomaly Check:

Z-score = (Transaction - Mean) / SD = (8500 - 1200) / 400 = 18.25 → 18.25 standard deviations above mean (extremely rare!) → Flag as potential fraud (investigate)

Threshold for Alerts:

  • Z-score > 3: Unusual (investigate, 0.3% false positive rate)
  • Z-score > 4: Very unusual (likely fraud, 0.006% false positive rate)

Why it works: Fraudulent transactions are outliers (many SD from mean). Legitimate transactions cluster around mean (within 2-3 SD).

Flipkart Example — Bulk Order Detection:

User's Order History: - Mean order value: ₹850 - SD: ₹300 New order: ₹25,000 (laptop + accessories) Z-score: (25000 - 850) / 300 = 80.5 → Flag for manual review (unusual for this customer) → Might be gift/legitimate bulk purchase (not fraud) → Or account compromised (verify with OTP)

Takeaway: SD enables automated anomaly detection. Extreme outliers (>3-4 SD) trigger alerts.

⚖️

High SD vs Low SD: What It Means

Standard deviation is context-dependent — "high" or "low" SD depends on the domain and what you're measuring.

When Low SD is Good

Consistency is valued:

  • Manufacturing (product dimensions should match specs)
  • Service delivery (consistent delivery times, response times)
  • Medical dosing (drug potency must be consistent)
  • Financial planning (predictable cash flow)

Example — Cloud Server Uptime:

Server A: Mean uptime 99.5%, SD 0.2% Server B: Mean uptime 99.5%, SD 2.0% → Both average 99.5%, but Server A is RELIABLE (low SD) → Server B has wild swings (might drop to 97.5% some months — unacceptable)

When High SD is Acceptable (or Expected)

Natural variability:

  • Human behavior (customer purchase amounts vary widely)
  • Creative output (article views, video engagement — some go viral, most don't)
  • Biological measurements (varies by person, conditions)

Diversification (in portfolios):

  • Want assets with different SD (some stable, some volatile) for balance
  • High-SD assets offer growth potential (with risk)

Example — YouTube Video Views:

Channel posts 50 videos: - Mean views: 10,000 - SD: 15,000 (high!) → Most videos get 1,000-5,000 views → A few viral videos get 50,000-100,000 views → High SD is normal (content variability)

Red Flags: When SD Changes Over Time

Increasing SD (process degrading):

  • Manufacturing: SD was 0.05mm, now 0.15mm → Machine needs maintenance
  • Delivery times: SD was 5 min, now 20 min → Operational issues (driver shortage, routing problems)

Decreasing SD (process improving):

  • Customer support: Response time SD dropped from 2 hours to 30 min → Better staffing/systems
  • Code deployment: Bug count SD dropped from 15 to 3 → Better QA process

Monitoring SD over time is key to quality control (called Statistical Process Control, SPC).


Comparing SD Across Different Scales

Problem: Can't directly compare SD of different units.

Example:

  • Heights: Mean 170cm, SD 10cm
  • Weights: Mean 70kg, SD 8kg

Which has more variability? Can't tell (different units).

Solution: Use Coefficient of Variation (CV):

CV = (SD / Mean) × 100% Heights: CV = (10 / 170) × 100% = 5.9% Weights: CV = (8 / 70) × 100% = 11.4% → Weights have MORE relative variability (despite smaller SD)

CV normalizes SD by mean (unit-less), enabling comparison.

Info

Rule of thumb: CV < 10% = low variability (consistent), CV > 30% = high variability (noisy data). Use CV to compare datasets with different scales or units.

⚠️ FinalQuiz error: Missing or invalid questions array

⚠️ SummarySection error: Missing or invalid items array

Received: {"hasItems":false,"isArray":false}