2 Data Preprocessing And Preparation

Data Warehousing and Data Mining · Unit 2

Data Preprocessing and Preparation

Exam-focused notes for Data Preprocessing and Preparation (Data Warehousing and Data Mining, BIT454): what the TU syllabus asks and how it has actually been tested, with 1 solved past questions from this unit.

Data Preprocessing and Preparation in short

Real data is often dirty, incomplete and spread over many sources. Data preprocessing prepares it before mining, because poor data gives poor results.

Data Preprocessing and Preparation: notes

Need for data preprocessing

Real-world data has three common problems:

  • Incomplete: some values or attributes are missing.
  • Noisy: it contains errors or outliers (for example, age = -5).
  • Inconsistent: the same thing is written in different ways (for example, rating "1, 2, 3" in one table and "A, B, C" in another).

Quality decisions need quality data. Preprocessing improves accuracy and also makes mining faster. The main tasks are data cleaning, integration, transformation and reduction.

Handling missing values and noise

Ways to handle missing values:

  • Ignore the record. This works only when few values are missing.
  • Fill in by hand. This is slow for large data.
  • Fill with a global constant such as "Unknown".
  • Fill with the attribute mean or median.
  • Fill with the mean of records in the same class.
  • Fill with the most probable value, found using regression or a decision tree.

Noise is a random error in a measured value. Ways to smooth it:

  • Binning: sort the values, split them into bins, and replace each value by its bin mean, median or boundary.
  • Regression: fit a line or curve and replace values by the fitted ones.
  • Clustering: values far from every cluster are treated as outliers.
  • Combined human and computer checking: the computer flags odd values and a person checks them.

Worked example of binning. Sorted prices: 4, 8, 15, 21, 21, 24, 25, 28, 34. Use equal-depth bins of 3 values each.

BinValuesSmoothing by meanSmoothing by boundary
14, 8, 159, 9, 94, 4, 15
221, 21, 2422, 22, 2221, 21, 24
325, 28, 3429, 29, 2925, 25, 34

For bin 1, the mean is $(4+8+15)/3 = 9$. With boundaries, each value moves to the closer of 4 or 15, so 8 becomes 4.

What this unit covers

  • Need for data preprocessing
  • Data cleaning and transformation methods
  • Data integration and consolidation
  • Data reduction techniques
  • Handling missing values and noise

Need for data preprocessing

2081 · 5 marks

Why is data preprocessing required? Explain any two data preprocessing methods. [5]

Show solved answer

Model Answer: Data Preprocessing

Why Data Preprocessing is Required (2 marks)

Data preprocessing is essential because:

  1. Raw data quality issues: Real-world data contains inconsistencies, missing values, duplicates, and noise that can negatively impact model performance and accuracy.

  2. Improved model performance: Cleaning and transforming data into a suitable format ensures that machine learning algorithms can learn patterns more effectively and make better predictions.

  3. Handling incompatibilities: Raw data may be in different formats, scales, or units. Preprocessing standardizes this to make it compatible with algorithms.

  4. Reduced computational cost: Removing irrelevant features and handling outliers reduces the data size and computational burden.

  5. Better insights: Preprocessed data reveals meaningful patterns and relationships that would otherwise be obscured by noise and errors.


Two Data Preprocessing Methods (3 marks)

1. Data Cleaning

Data cleaning involves identifying and correcting errors and inconsistencies in the dataset:

  • Handling missing values: Replace or remove records with missing data using techniques like mean imputation, forward fill, or deletion.
  • Removing duplicates: Identify and eliminate duplicate records that may skew analysis.
  • Correcting errors: Fix typos, inconsistent formatting, and logical errors (e.g., negative ages).
  • Handling outliers: Detect and manage extreme values that don't fit the normal distribution.

Example: In a student dataset, if some age values are missing, we can fill them with the mean age of the dataset.

2. Data Normalization/Standardization

This method scales numerical features to a common range:

  • Normalization: Scales data to a range [0, 1] using the formula: $$X_{normalized} = \frac{X - X_{min}}{X_{max} - X_{min}}$$

  • Standardization: Transforms data to have mean 0 and standard deviation 1: $$X_{standardized} = \frac{X - \mu}{\sigma}$$

Purpose: Ensures that features with different scales (e.g., age in years vs. income in thousands) contribute equally to model training.

Example: If age ranges 18-80 and salary ranges 20,000-500,000, normalization brings both to [0, 1] scale for fair comparison.

Open this answer on its own page →