What is data preprocessing in machine learning?
Data preprocessing is the set of steps that turn raw records into clean numeric input a model can train on. It typically covers handling missing values, scaling numeric features, encoding categorical ones, and splitting the data into training, validation, and test sets. Each step is learned from the training data and then applied unchanged to new data.
Preprocessing decides much of a model's quality before any training starts. Distance-based models such as KNN and SVM give wrong answers on unscaled features, most libraries reject text categories and empty cells, and a careless split can make a weak model look excellent. In practice, tools such as scikit-learn's Pipeline and ColumnTransformer bundle these steps so the same transformations run in training, evaluation, and production.
Key ideas
- Data preprocessing turns raw, messy records into clean numeric input a model can train on.
- Missing values can be dropped or imputed, and the right choice depends on why they are missing.
- Scaling puts features on comparable ranges, and outliers decide which scaling method works best.
- One-hot encoding suits unordered categories, and ordinal encoding suits categories with a real order.
- The data is split before any preprocessing step is fit, and every step is fit on training rows only.
- A pipeline applies the same learned transformations to training, test, and production data.
Common questions
What is the difference between data cleaning and data preprocessing?
Data cleaning fixes errors in the records: duplicates, typos, impossible values, and inconsistent units. Preprocessing is broader and also includes transformations that are not fixes, such as scaling, encoding, and splitting. Cleaning usually happens once on the dataset, while preprocessing steps are fit on training data and reapplied to every new input.
What is data leakage?
Data leakage is when information that would not be available at prediction time reaches the model during training. Fitting a scaler on the full dataset before splitting, or using a feature computed from the target, are common examples. Leakage makes validation scores look better than real-world performance.
Do neural networks need data preprocessing?
Yes, though less feature engineering. Inputs are still scaled, for example by subtracting each color channel's mean and dividing by its standard deviation for images. Text is tokenized into integer IDs, and missing values still need a decision before training.
How should outliers be handled?
First check whether an outlier is an error or a real extreme value. Errors are fixed or removed. Real extremes can be kept and handled with a log transform, clipping at a high percentile, robust scaling, or a model such as a decision tree that is less sensitive to them.
Related explainers
- Feature Scaling — Why and how to normalize features for faster convergence
- Feature Extraction — How networks find patterns in raw data
- Train, Validation & Test Sets — Splitting data to measure generalization and avoid overfitting
- Cross-Validation — K-fold, stratified, and leave-one-out evaluation
- Class Imbalance & Resampling — SMOTE, class weights, and metrics beyond accuracy
- Overfitting & Underfitting — The bias-variance tradeoff and generalization
References
- scikit-learn User Guide, "Preprocessing data"
- James, Witten, Hastie & Tibshirani, "An Introduction to Statistical Learning" (ISLR)
- Rubin (1976), "Inference and Missing Data", Biometrika
Last updated