How to Clean Data (RapidMiner)
How to Clean Data: Step-by-Step (+ RapidMiner operator)
Related
Order: profile → structure → type → standardize → range → missing → outliers → duplicates → integrate → transform → re-check.
Each step needs the step before it: you can't range-check "abc", and you can't dedupe " milk " vs "Milk" until both are standardized.
(Operators marked † weren't used in our homework, but they exist in AI Studio.)
| # | Step | What to do | Lecture check | RapidMiner |
|---|---|---|---|---|
| 0 | Know your data | Look at types, min/max, missing counts, distinct values, skew | — | Results → Statistics tab, histograms, Breakpoint After |
| 1 | Structure | Wrong number of fields (missing or extra comma) → quarantine, don't guess | Presence | Read CSV (Import Wizard shows broken rows), Filter Examples |
| 2 | Type | Text in a number field ("abc") → treat as missing | Type | Set types in the Read CSV wizard; Numerical to Polynominal / Nominal to Numerical |
| 3 | Standardize | One format per field: " milk "→MILK, M/Male→M, one date format, one unit | Format | Map, Replace†, Trim†, Generate Attributes (unit conversion), Rename |
| 4 | Range / rules | Impossible values (qty ≤ 0, price > max, GPS (0,0), 31 Sept) → remove or set missing. Turn sentinels (-1, -99999, N/A) into missing | Range | Filter Examples (custom filter, e.g. lat ≠ 0) |
| 5 | Missing | Choose a fill using the table below | Presence | Replace Missing Values; Filter Examples → no_missing_attributes |
| 6 | Outliers | Detect, then decide: noise → remove; valid → keep | Range | Detect Outlier (Distances) → Filter Examples (outlier = false) |
| 7 | Duplicates | Same record or same key twice → keep one (only after step 3) | Cross-record | Remove Duplicates†; or Aggregate by the key |
| 8 | Integrate | Combine sources; fix column-name mismatches (cust_id = cust_no) and the same entity with different names | — | Join (lookup table), Append (stack same columns), Rename |
| 9 | Transform | Scale, bin, aggregate, keep useful columns only | — | Normalize, Discretize, Aggregate, Pivot, Select Attributes, Sample, Set Role |
| 10 | Re-check | Run every validation check again; row counts before vs after | All | Statistics tab, Breakpoint |
Missing values: what to fill with?
Related
| Situation | Fill with | Why |
|---|---|---|
| The label (target) is missing | Drop the row | Useless for training ("ignore the tuple") |
| Missing means "none happened" (0 pings in an hour, no purchase) | 0 | 0 is the true value (HW2: Pivot → Replace Missing = 0 → X-Means) |
| Numeric, symmetric (height, temperature) | Mean | Keeps the average |
| Numeric, skewed or with outliers (income, price) | Median | The mean gets dragged by outliers. If mean > median, use the median |
| Categorical (color, occupation) | Mode or a new class "Unknown" | You can't average categories |
| Rows fall into classes | Mean/median of the same class | "Smarter": similar rows are alike |
| Time series (GPS, prices, sensors) | Forward / backward fill | Yesterday's price is the best guess for today |
| Other columns can predict it | KNN / regression / most probable value | Uses similar rows |
| A money or transaction fact (qty, amount) | Drop or verify, never impute | Imputing invents sales that never happened |
| Most of the column is empty | Drop the column | Too little signal to fill honestly |
| Only a few rows, lots of data | Listwise deletion (drop the rows) | Cheap, little bias |
| Keep rows, use what's there | Pairwise deletion | Loses less data |
When 0 is wrong: when 0 is a real, different value. A missing temperature ≠ 0 °C, a missing salary ≠ 0 THB, a missing age ≠ age 0.
In RapidMiner: Replace Missing Values offers average / minimum / maximum / zero / value (put the median or mode in yourself as a value). To drop missing rows, use Filter Examples → no_missing_attributes.
Quick flow: label? → drop · means none? → 0 · money fact? → drop/verify · time series? → ffill · category? → mode/Unknown · skewed? → median · symmetric? → mean · mostly empty? → drop the column
Outliers: valid or noise?
Detect: Z-score (|z| > 3), IQR (outside Q1 − 1.5·IQR / Q3 + 1.5·IQR), boxplot, clustering / DBSCAN, Detect Outlier (Distances).
| Type | Example | Action | RapidMiner |
|---|---|---|---|
| Noise (impossible, breaks a rule) | age 200, salary −10, price 4,000 when the max is 1,000, GPS (0,0) | Remove | Detect Outlier → Filter Examples |
| Valid (rare but real) | CEO salary, a 500-snack school order | Keep, reduce its effect: robust scaling, log, capping | Normalize (Z), Discretize |
| Unsure | a sudden spike | Flag and verify with the source | Keep the outlier column, don't filter |
Smooth noise instead of deleting it: moving average, bin means (equal frequency), low-pass filter.
Lesson from HW2 Ex3: removing outliers changed accuracy only 73.63% → 73.85%, so measure the effect; don't assume cleaning always helps.
Transform: which one?
| Need | Use | RapidMiner |
|---|---|---|
| Scale to [0, 1] | Min-max (sensitive to outliers) | Normalize → range transformation |
| Mean 0, std 1 | Z-score | Normalize → Z-transformation |
| Skewed data | Log transform / robust (median, IQR) scaling | Generate Attributes (log(x)) |
| Bins | Equal width (outliers dominate) / equal frequency | Discretize by Binning / by Frequency |
| One row per entity | Group-by / long → wide | Aggregate / Pivot |
| Less data | Sampling (stratified if skewed), feature selection | Sample (Stratified), Select Attributes, Weight by SVM → Select by Weights |
What counts as "clean"?
- ☐ Validation passes: presence, type, length, range, format
- ☐ Verification passes: values match business rules and real records
- ☐ No unexplained missing values: every fill has a reason, or the row/column was dropped
- ☐ No sentinels left (
-1,-99999,0,0,N/A) - ☐ Consistent: one format, one unit, one spelling per category
- ☐ No duplicates (by key)
- ☐ Outliers decided: noise removed, valid ones kept
- ☐ Totals reconcile: rows before vs after, sums match the source
- ☐ Documented: what was dropped and why (keep the rejected rows)
These map to the Data Quality dimensions (Lecture 3): Accuracy, Completeness, Consistency, Timeliness, Believability, Interpretability.
In MapReduce: per-record checks (structure, type, standardize, range) go in the mapper. Duplicates and a global mean for imputation need the reducer or another job, because a mapper sees only one record at a time.