📖 Data pre-processing: Preparing raw data so that mining gives good results. Real data is dirty, so this stage often takes most of the time of a project.
Raw data→Clean→Integrate→Transform (normalize)→Reduce→Ready for mining
| Task | What it does | Examples |
|---|
| Data cleaning | Fix errors, missing values, duplicates, inconsistencies | Fill with mean or median, remove duplicates |
| Data integration | Merge data from many sources | Join shop and website customer tables |
| Data transformation | Change form or scale | Normalization, aggregation, discretization |
| Data reduction | Make data smaller but keep the meaning | Remove columns, sampling, PCA |
1. Data cleaning
| Problem | How to handle |
|---|
| Missing values | Ignore the record, fill with mean / median / mode, use a constant, or predict the value |
| Noisy data | Binning (smooth using neighbours), regression, find and remove outliers |
| Duplicates | Detect matching rows and keep one |
| Inconsistency | Use one format and one spelling (M/F, Delhi) |
| ID | Name | Age | Gender | Income | City |
|---|
| 1 | Amit | 25 | M | 40000 | Delhi |
| 2 | Neha | (missing) | F | 52000 | Delhi |
| 3 | Raj | 230 | Male | 38000 | delhi |
| 4 | Amit | 25 | M | 40000 | Delhi |
| 5 | Sita | 31 | F | −5000 | Mumbai |
| 6 | Pooja | 28 | F | 60000 | Mumbai |
| ID | Name | Age | Gender | Income | City |
|---|
| 1 | Amit | 25 | M | 40000 | Delhi |
| 2 | Neha | 28 | F | 52000 | Delhi |
| 3 | Raj | 28 | M | 38000 | Delhi |
| 5 | Sita | 31 | F | 46000 | Mumbai |
| 6 | Pooja | 28 | F | 60000 | Mumbai |
After cleaning: duplicate removed, missing or impossible values filled with the median (age 28, income 46000), labels made consistent.
2. Normalization (scaling)
📖 Normalization rescales numeric columns to a common range, so a column with big numbers (income) does not overpower a column with small numbers (age).
| Income | Min–max | Z-score |
|---|
| 40000 | 0.09 | -0.89 |
| 52000 | 0.64 | 0.60 |
| 38000 | 0.00 | -1.14 |
| 46000 | 0.36 | -0.15 |
| 60000 | 1.00 | 1.59 |
Min = 38000, max = 60000, mean = 47200, population standard deviation = 8060.
💡 Decimal scaling: largest income 60000 → j = 5 gives 0.6 (less than 1), so v′ = v / 105.
| Pair | Distance on raw values | Distance after min–max |
|---|
| Amit (25, ₹40000) and Ben (26, ₹41000) | 1000 | 0.027 |
| Amit and Chris (60, ₹40500) | 501 | 0.875 |
Raw values say Chris is closer to Amit (501 < 1000), only because income has big numbers. After scaling, Ben (age 26) is correctly closer than Chris (age 60).
3. Other transformation and reduction ideas
- Aggregation: daily sales → monthly sales
- Discretization: age → young / adult / senior
- Encoding: city names → numbers (one-hot)
- Dimensionality reduction: keep fewer columns, e.g. PCA