Many data mining courses group data preprocessing into five major tasks: data cleaning, data integration, data reduction, data transformation, and data discretization. Each one deals with a different problem in raw data. The order is not fixed, and in practice the tasks overlap and often repeat.
Data cleaning
Cleaning fixes problems in the data itself. This includes filling in or dropping missing values, correcting obvious errors, removing duplicate records, and deciding what to do with outliers.
An outlier is not always an error. A very large purchase may be real, so check before removing it. Suppose a customer table has an age recorded as 250. That is almost certainly an entry mistake, so it can be corrected, or treated as missing and filled in another way.
Data integration
Integration combines data from several sources into one consistent dataset. Two tables may describe the same customers, but one calls the field cust_id and the other calls it customer_number. One table may store prices in dollars and another in cents.
Integration means matching fields, converting units, resolving conflicts between sources, and removing records that appear more than once because the sources overlap.
Data reduction
Reduction makes the dataset smaller while keeping most of its useful information. It can mean dropping columns that repeat each other or have no bearing on the question, selecting a sample of rows, or using a method such as principal component analysis (PCA). PCA combines correlated features into a smaller set of new features.
Smaller data can train faster and is often easier to inspect. Reducing too much, though, can throw away signal the model needs, so check the result.
Data transformation
Transformation changes values into a form that models handle better. Common examples include:
- Scaling numbers. Min-max scaling squeezes values into a fixed range, such as 0 to 1. Standardization rescales values so they have a mean of 0 and a standard deviation of 1.
- Encoding categories. One-hot encoding creates a separate yes-or-no column for each category, so a model can use labels such as “red” or “blue” as numbers.
- Aggregating. Daily sales might become monthly totals.
- Applying a mathematical function. A logarithm can compress a skewed value, such as income, so a few very large values do not dominate.
Data discretization
Discretization turns continuous values into a smaller set of intervals, or bins. Ages might become “under 18,” “18 to 34,” “35 to 64,” and “65 and over.” This can make some patterns easier to see, and some methods work better with categories than with continuous numbers.
Discretization also throws away detail, so it is a judgment call. Bins that are too wide can hide differences that matter.
How the tasks fit a machine learning project
Machine learning workflows often describe the work in other terms: collect the data, clean it, split it into training and test sets, encode and scale the features, then choose which features to keep. These steps overlap with the five tasks above.
One ordering rule matters most. Split the data before computing any scaling values or fill-in values, so the test set does not influence training. Doing this early helps avoid overly optimistic results, which is a common problem for beginners.
Tools that help
Python libraries cover most of these tasks. pandas handles cleaning and joining tables. scikit-learn includes tools for scaling, encoding, and filling in missing values, and it lets you fit those steps on training data and then reuse them on test data.
The five tasks explain the mechanics of preparation. For the bigger reason this work matters, read about the need of data preprocessing in machine learning. In short, models learn from whatever data they receive, and these steps decide what that data looks like.