Data Analytics & Business Intelligence · Chapter 4 · ~15 min · Intermediate
Exploratory Data Analysis (EDA): Distributions & Outliers
Uncover hidden distributions, calculate skewness and kurtosis, and isolate extreme outliers using IQR and Z-scores.
- Calculate 5-number summaries: Min, Q1, Median (Q2), Q3, and Max
- Detect positive (right) vs negative (left) skew using Pearson's skewness index
- Construct Tukey box plots using 1.5 * IQR inner and 3.0 * IQR outer fences
- Evaluate kurtosis to identify heavy-tailed risk in financial and operational data
Exploratory Data Analysis (EDA): Distributions & Outliers: learn it visually
Uncover hidden distributions, calculate skewness and kurtosis, and isolate extreme outliers using IQR and Z-scores.
1The 5-Number Summary & The Fallacy of Averages
Before running regressions, machine learning models, or presenting quarterly business reviews, every senior analyst performs Exploratory Data Analysis (EDA). Pioneered by legendary statistician John Tukey, EDA is the investigative art of letting the data reveal its true underlying structure rather than forcing predetermined assumptions onto it.
The most foundational tool of non-parametric EDA is the 5-Number Summary:
Min
0th PercentileQ1
25th PercentileQ2 / p50
50th PercentileQ3
75th PercentileMax
100th PercentileUnlike the Mean and Standard Deviation, which can be hijacked by a single massive enterprise purchase or server latency spike, percentiles are resistant statistics. If an e-commerce platform has 10,000 orders with a median of $42, a billionaire placing a $2,000,000 order will not budge the median by even one penny.
Why are the Median and Interquartile Range (IQR) called 'resistant' or 'robust' statistics?
2Mental Models: Bell Curves vs. Real-World Skewness
Examine the three fundamental misconceptions analysts make when analyzing distributions:
Wrong idea: Assume continuous data always follows a normal bell curve
Assuming customer spending, website session durations, or churn rates cluster symmetrically around the average like textbook Gaussian data.
Real system: Most business metrics follow right-skewed log-normal distributions
80% of users spend small amounts ($10-$50), while a long positive tail of 2% power users spend $5,000+. The Mean gets pulled far above the Median.
3Quantifying Distribution Shape: Skewness & Kurtosis
When analyzing a distribution, visual inspection must be paired with mathematical rigor. Two higher-order moments tell us the story of the curve:
Skewness (Asymmetry Index)
Measures the direction and extent of asymmetry. A symmetrical normal curve has Skewness = 0.
- Positive (Right) Skew (> 0): Tail stretches right toward high values (Mean > Median). Classic in income, order values, and housing prices.
- Negative (Left) Skew (< 0): Tail stretches left toward low values (Mean < Median). Common in human lifespans and product defect rates.
Kurtosis (Tail Fatness & Outlier Risk)
Measures the concentration of probability in the tails versus the center.
- Mesokurtic (Excess Kurtosis = 0): Standard normal curve.
- Leptokurtic (Excess > 0): Heavy tails and sharp peak. Extreme "Black Swan" events happen far more often than Gaussian models predict. Vital for risk analysis!
import numpy as np
import pandas as pd
from scipy import stats
def compute_distribution_metrics(series: pd.Series) -> dict:
"""Calculates comprehensive EDA distribution statistics."""
clean = series.dropna()
# 5-Number Summary
q1 = clean.quantile(0.25)
median = clean.median()
q3 = clean.quantile(0.75)
iqr = q3 - q1
# Tukey Outlier Fences
inner_lower = q1 - 1.5 * iqr
inner_upper = q3 + 1.5 * iqr
outer_upper = q3 + 3.0 * iqr
outliers = clean[(clean < inner_lower) | (clean > inner_upper)]
extreme_outliers = clean[clean > outer_upper]
return {
"count": len(clean),
"mean": round(float(clean.mean()), 2),
"median": round(float(median), 2),
"iqr": round(float(iqr), 2),
"skewness": round(float(stats.skew(clean)), 2),
"kurtosis": round(float(stats.kurtosis(clean)), 2),
"outlier_count": len(outliers),
"extreme_outlier_count": len(extreme_outliers),
"fences": (round(inner_lower, 2), round(inner_upper, 2)),
}4Interactive Simulator: Distribution & Box Plot Studio
Switch between four real-world analytical distributions. Observe how the median line stays anchored while the dashed mean marker gets pulled by long tails. Tweak the Tukey fence multiplier to see how outliers are flagged:
Live EDA Distribution & Tukey Box Plot Studio
Standard mild threshold is 1.5× IQR; extreme threshold is 3.0× IQR.
153.6 vs 48.5
Mean pulled right by tail+1.36
Strong Right Skew104.0
Q3 (135.0) - Q1 (31.0)[15, 291]
3 points exceed fence5Hands-On Challenge: Fix the IQR Outlier Detector
An analytics intern wrote a Python helper to flag outliers for the fraud team. However, they forgot to sort the input data before slicing quartile indices, inverted the IQR formula, and subtracted the upper fence instead of adding it. Fix the code so all tests pass:
🎯 Find and fix the bugs in the code above, then press Run & verify to test your solution.
Need a hint?
- Sort values:
sorted_vals = sorted(values)before extracting quartile indices. - Calculate IQR correctly as the difference between the 75th and 25th percentiles:
iqr = q3 - q1. - Add the spread for the upper fence:
upper_fence = q3 + 1.5 * iqr.
6Chapter Knowledge Challenge
Validate your understanding of distribution shapes, skewness, and quartile fences before moving to Business Metrics:
In a strongly right-skewed distribution of e-commerce customer transaction values, which statement is true?
A dataset of subscription durations has Q1 = 20 days and Q3 = 60 days. Using Tukey's 1.5 * IQR rule, what is the Upper Outlier Fence?
7Recap
- Exploratory Data Analysis (EDA): Always examine distributions visually before modeling. Summaries like averages conceal multi-modality, skewness, and outliers.
- The 5-Number Summary: Min, Q1 (p25), Median (p50), Q3 (p75), and Max provide an outlier-resistant picture of non-normal real-world data.
- Tukey's IQR Fences: Calculate bounds as
Q1 - 1.5*IQRandQ3 + 1.5*IQRto isolate anomalous records without depending on bell curve assumptions. - Skewness and Kurtosis: Skewness captures asymmetric tails (Mean vs Median divergence); Kurtosis flags heavy tails and high-impact Black Swan outlier probabilities.
Ready for Chapter 5 (Business Metrics & Unit Economics)? Mark this chapter as complete to proceed: