Impossible values and placeholders
Catch codes like -99 and values no real measurement could take, and write the rule that handles them.
You will be able to
- Recognize placeholder codes posing as data
- Write a valid-range rule from what you know about the subject
- Choose between marking a value missing, dropping the row and flagging it
Read first
A code posing as a number
ReadIn the customer list, age uses -99 for "unknown" on 22 rows. That is a sentinel valueSentinel valueA number that means "no number", such as -99 for an unknown age. Software can't tell, so it averages them with real values.: a number that means "no number". Software can't tell, so it averages them with real ages.
Other common ones are 999, 0 for "not recorded", and text such as n/a or a lone dash.
How far does one code move a mean?
PredictPredict first
Nine people have an average age of 40. A tenth has age recorded as -99. What is the mean of the ten values?
Make your guess between 0 and 45 years, then reveal.
Reveal
One code in ten pulled the mean down by about 14 years, and nothing in the output looks wrong.
Find them, then write the rule
In the appOpen Insights (⌘5) on the customer list. Findings report suspected placeholder values, negative values in columns that should be positive, and dates in the future. Fix in Prepare opens the fix.
Then, in Prepare (⌘3):
- Mark placeholders as missing handles codes and text tokens you name.
- Valid range rule treats anything outside a range as a problem. Age 0 to 120 is a rule; a statistical cut-off isn't.
Three things a rule can do
ReflectValid range rule can mark the value missing, drop the row or flag it.
- Mark missing keeps the row's other values. It is usually the right start.
- Drop the row fits when the whole record is unreliable.
- Flag keeps everything and adds a column, useful while you find out what happened.
An impossible value tells you something failed. Which of these would you want if 8 of the 22 codes came from one data-entry site?
Impossible isn't the same as unusual
ReadA 118-year-old is unusual, and a rule set at 120 lets that through for a human to check. A height of -5 cm can't exist. Handle errors with rules from subject knowledge, and treat unusual-but-possible values as outliers to investigate, which is a different job.
Check your understanding
CheckpointCheck yourself
Which is the better rule for age in an adult customer file?
Show the answer
Answer: a
A range comes from what ages can be. A z-score cut-off comes from the data, and the codes you are trying to catch distort its mean and SD.
Check yourself
A spend_30d column has many 0.00 values. What should you do?
Show the answer
Answer: b
Zero can be real or a code, and the numbers alone won't say. Ask, or look for patterns such as zeros clustered in one source.
Recap
Recap- Placeholder codes behave like real numbers until you find them.
- Valid-range rules come from subject knowledge, not from the distribution.
- Mark, drop or flag on purpose, and investigate what produced the errors.
Concepts in this lesson