Quiz 2

Data Visualization — Histograms, Shape, and Skewness

3061 words
15 min read
Python Week 1: the first filter for runtime behavior
Visual companion
Python
Type and operator map

Python Week 1: the first filter for runtime behavior

View
Revision summary

What this note is really saying

Short form

# Data Visualization — Histograms, Shape, and Skewness ## 🎯 Learning Objectives After completing this topic, you will be able to: - Construct and interpret **histograms** for continuous data - Create **frequency polygons** and **stem-and-leaf plots** - Identify distribution **shape** (symmetric, skewed, bimodal, un...

Data Visualization — Histograms, Shape, and Skewness

🎯 Learning Objectives

After completing this topic, you will be able to:
  • Construct and interpret histograms for continuous data
  • Create frequency polygons and stem-and-leaf plots
  • Identify distribution shape (symmetric, skewed, bimodal, uniform)
  • Recognize skewness and understand its implications
  • Choose appropriate visualizations based on data type and purpose

📋 Prerequisites


📖 Core Content

6.1 Intuition: A Picture Is Worth a Thousand Numbers

A list of 1,000 numbers tells you very little. A histogram of those same numbers can tell you in seconds:
  • Where the data is concentrated
  • How spread out it is
  • Whether it's symmetric or skewed
  • Whether there are gaps or clusters
  • Whether there are outliers Visualization is the bridge between raw data and insight. Before doing any formal analysis, you should always visualize your data.
Everyday analogy: Imagine describing a city by listing the height of every building (raw data). Now imagine seeing a skyline silhouette (visualization). The silhouette instantly tells you: which part of town has skyscrapers, where it's mostly low-rise, whether there's a clear downtown center. That's what visualization does for data. 🔑 Key Insight: Anscombe's Quartet (four datasets with identical mean, variance, correlation, and regression line) proved that visualizing data is essential — completely different patterns can have identical summary statistics.

6.2 Histograms

6.2.1 Intuition

A histogram divides the range of data into bins (intervals) and counts how many data points fall into each bin. It's like a bar chart for continuous data — but bars touch each other because the data is on a continuous scale.

6.2.2 Construction: Step-by-Step

Example: 20 students' test scores:
52, 55, 61, 63, 67, 68, 70, 72, 73, 75, 76, 78, 79, 81, 83, 85, 87, 90, 93, 98 Step 1: Find the range. Min = 52, Max = 98, Range = 46 Step 2: Choose number of bins. A common rule: Number of binsn\text{Number of bins} \approx \sqrt{n}. For n = 20, that's about 4-5 bins. For larger datasets, use 5-15 bins. Too few bins hide detail; too many bins create noise. Step 3: Determine bin width. Range / bins ≈ 46 / 5 ≈ 9.2. Let's use width = 10 for simplicity. Step 4: Define bin boundaries.
BinRangeFrequency
150-602 (52, 55)
260-704 (61, 63, 67, 68)
370-807 (70, 72, 73, 75, 76, 78, 79)
480-904 (81, 83, 85, 87)
590-1003 (90, 93, 98)
Step 5: Draw the histogram. (Diagram) Interpretation: Most scores cluster in the 70-80 range. The distribution is roughly symmetric, peaking in the middle.

6.2.3 Key Rules

RuleReason
Bars touchData is continuous — no gaps between intervals
Bin width should be equalUnequal widths distort the visual
Choose bins carefullyToo few = oversimplified, too many = noisy
Label axes clearlyTitle, X-axis (variable), Y-axis (frequency)

6.3 Frequency Polygons

A frequency polygon connects the midpoints of each bin with straight lines, creating a polygon. It's an alternative to histograms, especially useful for overlaying multiple distributions. Construction:
  1. Create a histogram
  2. Mark the midpoint of each bin at the correct height
  3. Connect the points with straight lines
  4. Close the polygon to the X-axis at both ends Advantages over histograms:
  • Easier to compare multiple distributions (overlay lines)
  • Shows the shape more cleanly
  • Useful for smooth distributions

6.4 Stem-and-Leaf Plots

A stem-and-leaf plot is a text-based display that shows the shape of the data and retains the actual values. Construction: Split each value into a "stem" (leading digits) and "leaf" (trailing digit). Example: Test scores: 52, 55, 61, 63, 67, 68, 70, 72, 73, 75, 76, 78, 79, 81, 83, 85, 87, 90, 93, 98
pseudo
Stem | Leaf
5    | 2 5
6    | 1 3 7 8
7    | 0 2 3 5 6 8 9
8    | 1 3 5 7
9    | 0 3 8
Interpretation: The plot looks like a histogram on its side. The 70s stem has the most leaves (7 values), matching our histogram. We can still read individual values (e.g., row "7 | 0 2 3 5 6 8 9" means 70, 72, 73, 75, 76, 78, 79).

6.5 Distribution Shape

The shape of a distribution describes how values are spread across the range.

6.5.1 Symmetric Distributions

The left and right sides are mirror images. (Diagram)
ShapeDescriptionExample
Bell-shaped (Normal)Single peak in center, tails taper equallyHeights, IQ scores
UniformAll values equally frequentRolling a fair die
For symmetric data: Mean ≈ Median ≈ Mode

6.5.2 Skewed Distributions

One tail is longer than the other. (Diagram)
ShapeDescriptionMean vs MedianExample
Right-skewed (positive)Long tail to the rightMean > MedianIncome, house prices
Left-skewed (negative)Long tail to the leftMean < MedianAge at death, exam scores (if easy test)
Why the relationship holds: The mean is pulled toward the tail more than the median.

6.5.3 Other Shapes

ShapeDescriptionExample
BimodalTwo distinct peaksHeights of men and women combined
MultimodalMultiple peaksMixed populations
J-shapedPeak at one end, tail at the otherNumber of sexual partners
U-shapedPeaks at both ends, dip in middleMortality rates by age (high infant mortality, high old-age mortality)

6.6 Box Plots and Shape

Box plots (from the previous topic) reveal shape: (Diagram)
  • Right-skewed: Right whisker longer, median closer to Q1 than Q3
  • Left-skewed: Left whisker longer, median closer to Q3 than Q1
  • Symmetric: Whiskers roughly equal, median near center of box

6.7 Common Visualization Mistakes

Mistake 1: Misleading Y-Axis

Starting the Y-axis at a non-zero value exaggerates differences. Fix: Always include zero on the Y-axis for bar charts. For histograms, the Y-axis should start at zero.

Mistake 2: Inappropriate Bin Width

Too few bins hide the shape; too many bins create noise. Example: If the test score histogram above had only 2 bins (50-75: 8, 75-100: 12), we'd miss the peak in the 70-80 range. Fix: Try different bin widths. The "right" number shows a smooth shape without oversimplifying.

Mistake 3: Using a Bar Chart for Continuous Data

Bar charts have gaps between bars (categorical data). Histograms have touching bars (continuous data). Fix: Use histograms for numerical continuous data, bar charts for categorical data.

6.8 Visualizing Categorical Data (Review)

Chart TypeBest For
Bar chartComparing frequencies across categories
Pie chartShowing parts of a whole (≤5 categories)
Pareto chartIdentifying the most important categories
Mosaic plotShowing two categorical variables together

6.9 Worked Examples

Example 1: Creating a Histogram (Easy)

Data: Ages of 25 survey respondents:
18, 19, 21, 22, 22, 23, 25, 25, 27, 28, 30, 31, 32, 34, 35, 38, 39, 40, 42, 45, 48, 50, 52, 55, 60 Create a histogram with 5 bins. Solution: Step 1: Range = 60 - 18 = 42 Step 2: Bin width ≈ 42/5 ≈ 8.4. Let's use 9 for clean boundaries.
BinRangeFrequencyValues
118-27818,19,21,22,22,23,25,25,27
227-36628,30,31,32,34,35
336-45538,39,40,42,45
445-54448,50,52
554-63255,60
Visual:
pseudo
18-27: ████████ (8)
27-36: ██████   (6)
36-45: █████    (5)
45-54: ████     (4)
54-63: ██       (2)
Shape: Right-skewed (more young respondents, tail of older ones). This makes sense for a general survey — young people are more likely to respond.

Example 2: Comparing Distributions (Medium)

Scenario: Two classes took the same test. Create side-by-side interpretations from their box plots: Class A: Min=55, Q1=65, Med=72, Q3=78, Max=92 Class B: Min=40, Q1=60, Med=70, Q3=82, Max=98 Compare the distributions. Solution:
FeatureClass AClass B
Center (Median)7270
IQR (Middle 50%)13 (65-78)22 (60-82)
Range37 (55-92)58 (40-98)
Low outlier?Min=55 (OK)Min=40 (possible outlier)
ShapeRoughly symmetric (whiskers balanced)Slightly right-skewed (right whisker longer)
Interpretation:
  • Class A performed slightly better on average (median 72 vs 70)
  • Class A was more consistent (IQR 13 vs 22) — most students scored in a narrow range
  • Class B had more variability — some students scored very high (up to 98) and some very low (down to 40)
  • The teaching approach might differ: Class A seems uniform, Class B has a mix of strong and weak students

Example 3: Stem-and-Leaf with Skewness (Harder)

Data: Household incomes (₹thousands): 15, 18, 22, 25, 28, 30, 32, 35, 38, 40, 45, 50, 55, 60, 70, 85, 120, 200, 350 Create a stem-and-leaf plot and describe the shape. Solution: Stem-and-leaf (stem = ten-thousands, leaf = thousands):
pseudo
1  | 5 8
2  | 2 5 8
3  | 0 2 5 8
4  | 0 5
5  | 0 5
6  | 0
7  | 0
8  | 5
9  |
10 |
11 |
12 | 0
...
20 | 0
...
35 | 0
Shape analysis:
  • Right-skewed (positive skew) — clearly visible
  • Most values cluster in the lower stems (15-70)
  • A long tail stretches to 350
  • This is typical income data: most households earn modest amounts, a few earn very high amounts Impact on central tendency: Mean > Median (mean pulled right by the high earners)

6.10 Edge Cases & Gotchas

All Values in One Bin

If all data points fall into a single bin, the histogram is a single rectangle. This means either: (a) the data truly has no variability, or (b) the bins are too wide.

Gaps in the Data

If there are gaps (bins with zero frequency), these are real features. For example, if test scores show no one scored between 40-50, that might indicate a cutoff or a natural division.

Outliers in Histograms

A bar separated far from the main cluster indicates outliers. In our income example, the 350 bar would be far to the right of the main cluster.

6.11 Why This Matters

Data visualization is the first step in any analysis:
  • EDA (Exploratory Data Analysis): Visualize first, model second
  • Communication: A well-designed chart communicates more effectively than a table of numbers
  • Quality control: Histograms reveal anomalies in manufacturing processes
  • Scientific discovery: Many breakthroughs came from pattern recognition in visualizations (e.g., John Snow's cholera map) This connects to:
  • Week 4 (Contingency Tables): Visualizing relationships between variables
  • Week 12 (Normal Distribution): The bell curve shape
  • BSMA1004 (Stats 2): Residual plots for regression diagnostics

📐 Key Formulas / Concepts

ConceptDescriptionWhen to Use
HistogramBars (touching) showing frequency in binsContinuous numerical data
Frequency PolygonLine connecting bin midpointsOverlaying multiple distributions
Stem-and-Leaf PlotText display retaining individual valuesSmall datasets, quick EDA
SymmetricMirror-image distributionUse mean and standard deviation
Right-SkewedLong tail on right (Mean > Median)Use median and IQR
Left-SkewedLong tail on left (Mean < Median)Use median and IQR
BimodalTwo peaksLook for subgroups in data
UniformAll values equally frequentCould indicate random process
Box PlotFive-number summary visualizationComparing distributions
Bin WidthRange/n\text{Range} / \sqrt{n} (rough guide)Should balance detail and clarity

⚠️ Common Pitfalls

Pitfall 1: Confusing Histograms and Bar Charts

The mistake: Creating a bar chart (with gaps) for continuous data, or a histogram (no gaps) for categorical data. Why it happens: Both use bars. The visual difference is subtle. How to distinguish:
  • Bar chart: Gaps between bars → categorical data
  • Histogram: Bars touch → continuous data

Pitfall 2: Misinterpreting Skewness Direction

The mistake: Saying "right-skewed" when the peak is on the right (actually the tail is on the right). Why it happens: People focus on where the peak is, not where the tail is. Memory trick: The SKEW is in the TAIL. If the tail is on the right → right-skewed. The peak is on the left.

Pitfall 3: Ignoring the Sample Size

The mistake: Drawing strong conclusions about shape from too few data points. Why it happens: With n=10, a histogram can look very different with just one more data point. How to avoid: For shape analysis, you generally need at least 25-30 data points. With fewer, be cautious about interpreting shape.

Pitfall 4: Over-interpreting Small Bumps

The mistake: Seeing a small secondary bump and calling it bimodal when it's just random variation. Why it happens: With narrow bins, histograms can look "bumpy." How to avoid: Try wider bins. If the bump persists across different bin widths, it's real.

📝 Practice Questions

Q1: Histogram Construction
Create a histogram (6 bins) for: 2, 3, 5, 6, 7, 8, 8, 9, 10, 10, 11, 12, 13, 14, 15, 16, 18, 20, 22, 25
<details> <strong>Solution</strong>
Range = 25 - 2 = 23 Bin width ≈ 23/6 ≈ 3.83 ≈ 4
BinRangeFrequencyValues
12-652,3,5,6
26-1077,8,8,9,10,10
310-14411,12,13
414-18214,15,16
518-22118,20
622-26122,25
Wait, let me recount more carefully:
Values sorted: 2,3,5,6,7,8,8,9,10,10,11,12,13,14,15,16,18,20,22,25
BinRangeFrequencyIndices
2-62-5.9942,3,5,6
6-106-9.9957,8,8,9
10-1410-13.99510,10,11,12,13
14-1814-17.99314,15,16
18-2218-21.99218,20
22-2622-25.99122,25
Shape: Right-skewed (long tail toward higher values).
</details> > **Q2: Shape Identification** > > Identify the shape of each distribution: > > a) Mean = 50, Median = 50, Mode = 50 b) Mean = 35, Median = 30, Mode = 25 c) Mean = 80, Median = 85, Mode = 90 > > <details> <strong>Solution</strong> > > a) **Symmetric** — all three measures equal → symmetric distribution > > b) **Right-skewed** (positive skew) — Mean > Median > Mode → tail on the right > > c) **Left-skewed** (negative skew) — Mean < Median < Mode → tail on the left > > **Memory check:** The mean is pulled toward the tail. In (b), mean is larger (pulled right), so tail is right. </details> > **Q3: Stem-and-Leaf** > > Create a stem-and-leaf plot for: 12, 14, 18, 21, 23, 25, 28, 30, 33, 35, 37, 40, 42, 48, 51 > > <details> <strong>Solution</strong> > > ```pseudo > Stem | Leaf > 1 | 2 4 8 > 2 | 1 3 5 8 > 3 | 0 3 5 7 > 4 | 0 2 8 > 5 | 1 > ``` > > **Interpretation:** The distribution is roughly symmetric, with a slight concentration in the 20s and 30s. There's one value in the 50s (51) as a mild outlier. </details> > **Q4: Bin Width** > > A dataset has 100 values, range = 50. How many bins would you recommend for a histogram? > > <details> <strong>Solution</strong> > > Using $\sqrt{n}$: $\sqrt{100} = 10$ bins > > Bin width ≈ 50/10 = 5 > > So: 10 bins of width 5 each. > > This is a starting point — you might adjust based on the data's natural groupings. </details> > **Q5: Box Plot from Histogram** > > A histogram shows: left tail short, right tail long, peak on the left. Sketch the approximate box plot. > > <details> <strong>Solution</strong> > > This describes a **right-skewed** distribution. > > Box plot characteristics: > > - Left whisker: short > - Box: median closer to Q1 (left side of box) > - Right whisker: long > > ```pseudo > |----|--|------| > Min Q1 Med Q3 Max > ``` > > The right whisker (Q3 to Max) is longer than the left whisker (Min to Q1). The median is on the left side of the box. </details> > **Q6: Real-World Shape** > > For each variable, predict the shape and explain your reasoning: > > a) Time taken by students to complete an exam b) Number of goals scored per match in football c) Height of all adult humans > > <details> <strong>Solution</strong> > > **a) Exam completion time — Right-skewed** > > - Most students finish within a moderate time (say 45-60 min) > - A few students take much longer (the tail extends right) > - Very few finish extremely fast (hard to finish faster than a minimum time) > > **b) Goals per match — Right-skewed** > > - Most matches have 0-3 goals > - A few high-scoring matches (5+ goals) create a right tail > - Cannot have negative goals > > **c) Adult height — Roughly symmetric (bell-shaped)** > > - Heights cluster around the mean for each gender > - Equal number of people slightly above and slightly below average > - Extreme heights are rare in both directions > - Note: This is actually bimodal if we don't separate genders (men and women have different means) </details> > **Q7: Histogram Comparison** > > Two datasets have the same mean and standard deviation. Dataset A's histogram is bimodal. Dataset B's histogram is bell-shaped. What does this tell you? > > <details> <strong>Solution</strong> > > The identical mean and standard deviation don't reveal that these datasets are fundamentally different: > > **Dataset A (Bimodal):** > > - Likely contains two distinct subgroups (e.g., men and women, or two different treatment groups) > - The mean falls between the two peaks and may not represent either group well > - The standard deviation is inflated because of the gap between groups > > **Dataset B (Bell-shaped):** > > - Likely from a single homogeneous population > - The mean represents a "typical" value well > - The standard deviation reflects natural variation within one group > > **Lesson:** Always visualize! Summary statistics alone can be very misleading. </details> > **Q8: Application** > > A factory monitors the weight of cereal boxes (labeled 500g). The filling machine produces a symmetric distribution with mean 505g and standard deviation 3g. > > a) Sketch the distribution shape. b) What percentage of boxes are underweight (< 500g)? c) If the machine shifts to mean 500g, what changes about the distribution? > > <details> <strong>Solution</strong> > > **a) Shape:** Bell-shaped (normal distribution), centered at 505g, spread of about ±3g. > > **b) Underweight boxes:** > > - 500g is (500 - 505)/3 = -1.67 standard deviations below the mean > - Using the empirical rule: roughly 5% of data falls beyond ±2 s.d. > - More precisely: about 4.75% of boxes weigh less than 500g (this uses the Z-table which we'll learn later) > > **c) If mean shifts to 500g:** > > - The distribution centers exactly at 500g > - Now 50% of boxes are underweight (below 500g) > - This is why factories set the mean slightly above the label weight — to minimize underweight packages </details> * * * ## 🔗 Cross-References - **Next topic:** [Contingency Tables](/notes/01-foundation-bsma1002-stats-1-week04-06-contingency-tables) — visualizing relationships between two categorical variables - **Previous:** [Dispersion & Percentiles](/notes/01-foundation-bsma1002-stats-1-week03-04-dispersion-percentiles) — box plots as visualization of spread - **Week 12 (Normal Distribution):** The bell curve and the empirical rule - **BSMA1004 (Stats 2):** Residual plots for model diagnostics - **BSCS2004 (ML Foundations):** EDA is the first step in any ML project [Join Discord](https://discord.gg/gE2m4Qrdqv) [Previous**Dispersion & Percentiles**](/notes/01-foundation-bsma1002-stats-1-week03-04-dispersion-percentiles)[Next**Contingency Tables**](/notes/01-foundation-bsma1002-stats-1-week04-06-contingency-tables)
Document outline

Keep your place and jump directly to a heading.

Table of Contents
System Normal // Awaiting Context

Intelligence Hub

Navigate the knowledge graph to generate context. The Hub adapts dynamically to surface backlinks, related notes, and metadata insights.