What to notice & try
What to notice
- The same two students come back on several tabs: the 54 h and 64.5 h in Study hours raise the mean you would fill with from 6.86 to 8.40 h (Distribution, Statistics Comparison), inflate the std the Z-score uses (Outliers) and squeeze everyone else into three bars (Distribution).
- The synthetic income column is shared too: Imputation Lab fills it in, Outliers flags its long tail, Distribution log-transforms it.
- Elsewhere in the course: is a far-out dot in a scatter plot an error or a real extreme? → Lecture 1 › Scatter Plot. Why columns in different units are standardized first → Lecture 5 › PCA 2D Projection (MATH_SCALE in the code) and Parallel Coordinates › Car Data (Shared raw scale).
Try this
- Open Imputation Lab with Fill with mean: the mean shift is +0.00 on both rows, but the median shift is +0.06 std on the symmetric row and +0.19 std on the skewed one — three times as much.
- Open Missingness Pattern and switch 'Who is missing?' through its three options with Fill with mean: the gap to the true mean goes from −0.13 h to +0.64 h to +1.02 h.
What to notice & try
What to notice
- Gray triangles are the students whose study hours are missing: we still know their attendance, so they sit in the 'missing' row at the bottom. Hollow gray circles show their true values — something real data never shows you.
- Completely at random (MCAR): the triangles spread across the whole axis, and the mean of what we see (red line) lands right next to the true mean (dashed black line) — a gap of −0.13 h.
- Low-attendance students skip the survey (MAR — missingness depends on another column we do observe): 36 of the 38 triangles sit below 70 % attendance. Those left study more than the class, so the observed mean is 0.64 h too high, and both Drop rows and Fill with mean keep it there: 34 of the 38 diamonds land above their true circles, typically by 2.5 h.
- Students who study little don't report it (MNAR — missingness depends on the hidden value itself): even Predict from attendance leaves a +0.68 h gap, because attendance explains only part of why these answers are missing.
Try this
- Switch 'Who is missing?' to Completely at random: the red line lands right next to the black one, and even Fill with mean leaves the mean almost where it should be.
- With Low-attendance students skip the survey, set the method to Predict from attendance: the gap shrinks from +0.64 h to −0.07 h. The diamonds now follow the trend of their true circles instead of sitting above them — each still misses by about 1.2 h, because a straight line can't know one student's own scatter.
- In the code, set MISSING_SHARE = 0.5 and Run: with Low-attendance students skip the survey, the gap after Fill with mean more than doubles, to +1.46 h, while Predict from attendance still lands at −0.22 h. Switch to Students who study little don't report it: Predict now leaves +1.36 h.
- Turn off Show the true values: this is what real data looks like — no circles, no true mean, no gap. The triangles bunched on the left are the only clue, and they look much the same for Students who study little don't report it (27 of 38 below 70 %), where predicting from attendance won't close the gap.
What to notice & try
What to notice
- Each fill keeps its own statistic in place and shifts the other one: Fill with mean always shows a mean shift of +0.00, Fill with median a median shift of +0.00. The number to watch is the other one.
- On the symmetric row the mean and median almost coincide, so either fill barely moves the other statistic (at 20 % missing: under 0.1 std). On the skewed row they sit far apart: Fill with mean drags the median up by 3.52 $K (0.19 std), Fill with median pulls the mean down by 1.09 $K (0.06 std). The std units let you compare cm with $K.
- Fill with mode keeps neither statistic: on the skewed row it pulls both down (at 20 %: mean −1.85, median −2.55 $K). For a measured value the 'mode' is just the peak of a smoothed curve — even on the symmetric row it lands 1.4 cm from the median. The mode is the fill for categories, not for measurements.
- Every fill shrinks the Std, on both rows — the filled-in values all sit on one spot and add no spread (Fill with mean at 20 % missing: 8.44 → 7.55 cm and 18.34 → 16.40 $K). Drop rows leaves the Std where it was; it costs sample size instead.
Try this
- At 50 % missing, compare Fill with mean and Fill with median on the skewed row: mean-fill moves the median by +5.53 $K, median-fill moves the mean by −2.76 $K. On the symmetric row neither shifts anything by more than 0.6 cm.
- Watch the Std numbers: they drop on every fill method, by almost the same share on both rows. Switch to Drop rows and they stay where they were.
- With Fill with mean, look at the density curve on the skewed row: after filling it grows a second peak where the filled-in values sit — a shape the real data never had.
- In the code, set RANDOM_DRAWS = True and Run with Fill with mean: each hole now gets its own randomly drawn observed value (hot-deck imputation). The orange spike is gone, the Std barely drops (8.44 → 8.26 cm, 18.34 → 17.69 $K), and every shift stays under 0.1 std.
What to notice & try
What to notice
- Stars are the values the rule flags, and the legend under the chart lists them: 22 hours of sleep a night is an entry error; scores of 2 and 3 deserve a question (a missed exam? points out of 10?); and a score of 92, flagged by Z-score at 1.5, is simply the best student.
- Removing or clipping a few extreme values moves the mean a lot and the median hardly at all (Study hours: mean 8.40 → 6.86, median 7.10 → 6.90). The median ignores how far out a value is — but not how many values you take away.
- The threshold means different things for the two rules. For bell-shaped data the 1.5 × IQR fence sits about 2.7 std from the mean, so Z-score at 1.5 flags far more: on Stress level it flags 15 perfectly ordinary answers, where IQR flags none.
- Z-score measures with the mean and std, which the outliers themselves inflate: the two extreme students raise the std of Study hours from 2.4 to 9.2 h, so |z| > 3 puts the upper fence at 36 h — twice as far out as the IQR fence at k = 3 (18.6 h), although on bell-shaped data that one is the looser (about 4.7 std vs. 3).
Try this
- Sleep hours (the default): the rule flags a single value, 22 hours of sleep a night. Removing it cuts the Std by 45 % (2.06 → 1.13) and moves the mean by 0.21 h; the median stays at 7.50.
- Pick Score and switch Detection between IQR fence and Z-score at threshold 1.5: IQR flags only the scores of 2 and 3, Z-score also flags 42 and 92 — the best student in the class. Raise the threshold to 3 and the two rules agree again.
- Pick Income: 1.5 × IQR flags 27 of 300 values — the real top earners, not errors. The rule assumes roughly symmetric data: after a log transform (Distribution tab) the tail becomes short, and the same rule would flag only 3 of these 27.
- Pick Study hours and set Handling to Clip to fence: n stays 68, but the two students at 54 and 64.5 h are now at 13.7 h — a value nobody reported.
- In the code, set EXTRA_VALUES = [60, 70, 80], pick Study hours and Z-score at threshold 3: the student at 54 h is no longer flagged — the added extremes inflate the std from 9.2 to 15.4 h and push the fence out to 57 h. Switch to IQR fence at 1.5: it still flags all five.
What to notice & try
What to notice
- Both panels share the same y-axis. Fill with mean/median, Normalize and Standardize keep the raw panel's bins, so a bar that changes height on the right really gained or lost records. Remove outliers and Log transform cover a new range with new bins — compare their shape, not individual bars.
- Normalize (min–max) computes (x − min) / (max − min), which puts every value between 0 and 1. Standardize (z-score) computes (x − mean) / std: 0 is the mean, and +2 is two standard deviations above it. Both are linear, so only the axis numbers change and the bars stay exactly the same.
- Log transform is not linear: it squeezes big values together and spreads small ones apart, so a long right tail is pulled in. On Income (synthetic, right-skewed) the skew almost disappears, and the mean and median lines, 5 $K apart before, land on top of each other.
- Orange is the filled-in part of a bar: one value repeated, stacked on top of the real ones. The two synthetic columns are generated complete, so the Fill options have nothing to fill there.
Try this
- Study hours with Log transform (the default): the students at 54 and 64.5 h move in from 5.0 and 6.1 std above the mean to 3.7 and 4.0. But look left: the log stretches the five students below 3 h into a new left tail — the bulk of this column was never skewed, only its two extreme values made it look that way. Income (synthetic, right-skewed) is the case the log is made for.
- Switch between Raw, Normalize and Standardize: the bars don't move at all, only the numbers on the x-axis change. The two students at 54 and 64.5 h still keep the other 66 in the first three bars — rescaling doesn't fix outliers.
- Pick Income (synthetic, right-skewed) and compare Remove outliers with Log transform: removing cuts off 27 of 300 real values, and what is left is still right-skewed (mean 13.31 vs. median 11.81) with a new tail the same rule would trim again; the log transform keeps all 300 and makes the shape nearly symmetric (mean 1.11, median 1.10).
- In the code, set TRANSFORM = np.sqrt and Run on Income (synthetic, right-skewed): a milder squeeze — the tail is shorter, but the mean (3.88) still sits clearly above the median (3.54). Then try np.log: exactly the same shape as log10, only the numbers on the axis change.
What to notice & try
What to notice
- Every row draws the same statistics: the line runs from min to max, the red tick (upper half) is the mean and the purple tick (lower half) the median — when they meet end to end, the two are equal. The dashed outline in rows A and B is the raw row, so you can see what moved.
- The box is not a box plot: it is mean ± 1 std, centered on the mean, so a few extreme values can stretch it even below 0 h (Study hours).
- Fill with mean puts every filled-in value (orange triangle) on the mean: the red tick stays where it was, but the box gets narrower, because those values add no spread of their own (Study hours: std 9.21 → 8.49).
- On Study hours, Remove outliers drops just two records: the line's right end falls from 64.5 to 11.6, and the box shrinks to about a quarter of its width (std 9.21 → 2.41, −74 %).
Try this
- Set Method B to Fill with median, so A and B are the two fills: on Study hours each keeps its own tick in place and moves the other (A: median 7.10 → 7.55; B: mean 8.40 → 8.21). Now pick Score, where two very low scores (2 and 3) pull the mean below the median: mean-fill pulls the median down instead, 68.00 → 67.01.
- Pick Stress level with Fill with mean: the red tick stays put, but the purple one moves from 3 to 3.66 too — the nine filled-in values (3.66) sort between the 3s and the 4s, exactly where the middle of the sorted list falls. No student on a whole-number scale could have answered 3.66.
- On Score, compare Fill with mean against Fill with zero: zero puts the seven filled-in values at 0, below every real score, so the mean tick moves left (67.01 → 61.15, −9 %) and the box stretches (std 15.75 → 24.18, +54 %).
- In the code, set EXTRA_VALUES = [999] — one mistyped score — and pick Score: the raw mean jumps from 67.01 to 79.61 and the std from 15.75 to 108.74, while the median stays at 68.00. Remove outliers (row B) drops the typo together with the 2 and the 3.
No parameters for this demo.
Completely at random = MCAR. Depends on attendance, which we observe = MAR. Depends on the hidden value itself = MNAR.
Predict from attendance fits a straight line through the students we can see and reads each missing value off it.
Real data never gives you these — turn it off to see what you would actually have.
Watch the orange 'filled in' part of the bars grow as more of the data becomes invented rather than observed.
Try mean vs. median with the same missing rate — the skewed row is where they disagree most.
Fewer bins hide detail, more bins show noise — part of the shape you see is this choice.
The smoothed curve makes the fill's spike easy to spot: a peak the real data never had.
Sleep hours has one impossible value; Income has a long tail of real, very high values.
IQR uses the quartiles, which barely move when a few values are extreme; Z-score uses the mean and std, which those values pull.
Clipping keeps the sample size the same; removing shrinks it.
IQR fence: k × IQR beyond the quartiles (1.5 is Tukey's rule). Z-score: this many standard deviations from the mean.
Real columns have real-world noise; the two synthetic options are clean ideal shapes, easier to read a preprocessing effect off of.
Normalize and Standardize only relabel the x-axis; the log transform reshapes a skewed column without dropping anything.
Fewer bins hide detail, more bins show noise — part of the shape you see is this choice.
A smoothed outline of the bars — it shows the shape without the bin edges' jumps.
The std and the min–max range react to one extreme value far more than the median does.
Study hours, Sleep hours and Score each hide a few extreme values (Remove outliers drops 2, 1 and 2 of them); Stress level is a whole-number scale.
Filling puts the records with a missing value back into the count; Remove outliers drops records. Each row's label shows how many.
Same choices as A; each starts from the raw data, not from A's result.