Unusual, or just low?
Problem 23 dealt with values that were never recorded. This one deals with values that were recorded and look wrong. A mark of 12 in a class sitting in the seventies might be a real student who had a bad day, or a typing slip for 72, or a mark out of 20 that got into the wrong column. You cannot tell from the number alone — but you can tell that it deserves a second look, and that is a decision a rule can make for you.
marks.quantile(0.25) and marks.quantile(0.75). The number in the brackets is a proportion, so it runs from 0 to 1 — not a percentage.q3 - q1. The width of that middle half, and a measure of spread that one extreme value cannot disturb.That is its advantage over the standard deviation from problem 19. A single mark of 12 pulls the average down and pushes the standard deviation up, so both are affected by the very value you are trying to judge. Q1 and Q3 barely move.
q1 - 1.5 * iqr and q3 + 1.5 * iqr. Anything outside them is worth looking at.The 1.5 is a convention, not a law of nature. It is wide enough that ordinary variation stays inside and narrow enough to catch genuine oddities, and it has been in use long enough that a reader will understand what you did without being told.
The class you are given
Nine marks between 62 and 81, and one of 12. Sorted onto a number line, with the middle half shaded and the two fences dashed:
The middle half is narrow — seven marks wide — so the fences sit at 58 and 86. Every ordinary mark falls comfortably inside. The 12 is nowhere near, and the rule found that without anybody deciding in advance what counted as too low.
|, not the word or, and each condition needs its own brackets:(marks < low_fence) | (marks > high_fence)Use
& and you have asked for marks that are below 58 and above 86 at the same time, which nothing can be. The answer comes back empty and perfectly calm.What you are building
Build the programme
Your plan
The steps still to place
The whole programme is laid out below. Five pieces are missing. One of them stops the programme; the rest move the fences, and a fence in the wrong place either misses the odd value or flags half the class.
Leave nothing on "choose…". A wrong pick does not always cause an error — sometimes it just prints something you did not expect, which is the harder kind of mistake to spot.
Run and read
Here is the whole programme. Two files are available: one with an unusual mark in it, and one where the same ten students all sat in a narrow band. Run both — a rule that finds nothing when there is nothing to find is doing its job too.