2.1.14 · D3Data Preprocessing & Feature Engineering

Worked examples — Exploratory data analysis (EDA) workflow

5,160 words23 min readBack to topic

First, earn every symbol

Before a single example, let us make sure nothing is assumed. The parent note wrote this formula:

Now let us slowly read the formula out loud, symbol by symbol.

Covariance — the honest name for the top of the fraction

and use the SAME — so it cancels

Now watch the vanish. Rewrite using covariance and the two 's:

Why can never exceed 1 — the geometric reason

The "unitless shape" story is nice, but why is trapped in ? Here is the visual argument.

This is precisely the Cauchy–Schwarz inequality, , which says the dot product can never beat the product of the lengths — geometrically, a projection is never longer than the thing you project. Figure s01 shows the two arrows and the angle.

Read figure s01 (alt-text: two vectors and their angle). On the left panel, the raw data: five blue dots, a red dashed mean-cross at splitting the plane into four quadrants, and a small green arrow from the cross to each dot — every arrow lands in the "agree" quadrants (both-above or both-below), the visual meaning of near . On the right panel, the same data re-drawn as the two big arrows (x-deviations, blue) and (y-deviations, yellow) with the angle between them marked in red; because is small, . The narrow angle is the whole reason is nearly 1.

Everything below uses only these ideas. Prerequisites live in 2.1.15-Statistical-measuresfor-data-analysis (mean, std, median) and 2.1.16-Data-visualization-techniques (scatterplots, boxplots).


The scenario matrix

Every correlation / univariate situation falls into one of these cells. The examples that follow are labelled with the cell they cover, and together they hit every row.

# Case class What's special Example
A Strong positive () points hug a rising line Ex 1
B Strong negative () points hug a falling line Ex 2
C No linear relation () shapeless blob Ex 3
D Curved but (degenerate meaning) perfect pattern, zero Ex 4
E Zero-spread column () & tiny- denominator , undefined; edge case Ex 5
F Outlier hijack one point flips the number Ex 6
G Skew: mean vs median (univariate) which way the tail points Ex 7
H Categorical vs numerical (grouped stats) word problem / business decision Ex 8
I Exam twist: correlation ≠ causation & multicollinearity interpretation trap Ex 9
J Moderate + sample size / significance is real or luck? Ex 10

Example 1 — Cell A: strong positive correlation


Example 2 — Cell B: strong negative correlation

Read figure s02 (alt-text: downward best-fit line hugged by points). The red line is the best-fitting straight line through the five blue dots; it slopes downward. Every dot hugs that line closely — the visual signature of near 1. Compare it mentally with figure s01: same tightness, opposite tilt. Tilt direction = sign of ; tightness of the hug = magnitude of .


Example 3 — Cell C: no linear relationship


Example 4 — Cell D: perfect pattern, but (a trap!)

Read figure s03 (alt-text: dots on a symmetric parabola with mean line). The green curve is the exact parabola ; the blue dots sit perfectly on it — a flawless relationship. Yet the red dashed horizontal line marks , and you can see the dots are arranged symmetrically left-and-right about the vertical mean line: for every dot that pulls the product positive on the right, a mirror dot cancels it on the left. That left-right symmetry is why the votes sum to zero.


Example 5 — Cell E: a constant column () and the edge case


Example 6 — Cell F: one outlier hijacks the number

Read figure s04 (alt-text: four collinear dots plus one far-off red dot). Four blue dots line up on a perfect diagonal — that cluster alone would give . The red dot at the bottom-right is the typo ; the red arrow labels it "one bad row flips r to −0.67". Because that one point sits so far below everything, it single-handedly drags the mean of down and reverses the sum of products. The lesson is visual: one point far from the crowd can outvote all the others.


Example 7 — Cell G: mean vs median tells you the skew direction


Example 8 — Cell H: categorical vs numerical (business word problem)


Example 9 — Cell I: exam twist — high that lies


Example 10 — Cell J: a moderate — real signal or lucky noise?


Recall

Recall In one sentence, what is

? A single number in measuring how tightly two columns rise-and-fall together in a straight-line way: rising line, falling line, no linear link. Geometrically it is between the two deviation-arrows.

Recall Where does the

go — population vs sample? Both top () and bottom (, each carrying ) contain one factor of ; they cancel. So is unaffected by whether you divide by or not — the constant is irrelevant as long as top and bottom match.

Recall Why can

never exceed 1? Because and Cauchy–Schwarz says — a projection is never longer than the vector itself.

Recall What is covariance and how does it relate to

? — average co-movement in raw units. Then : covariance divided by the two spreads to make it unit-free.

Recall

for . Does that mean no relationship? (Ex 4) No — it means no linear relationship. Pearson is blind to curves; always plot the scatter.

Recall What happens when a column is constant, and why isn't that

? (Ex 5) Its std is , so has zero length and there is no angle to take a cosine of → is undefined (NaN), not . "" would falsely claim "measured, no link"; the truth is "could not measure". Drop zero-variance columns.

Recall Why is

always when ? (Ex 5) Two points determine one line perfectly — no scatter to disagree, so the deviation-arrows are exactly parallel/anti-parallel. Never trust a