DL Notes
Learn essential data preprocessing techniques for deep learning including normalization, augmentation, handling missing data, and creating data pipelines.
There is a saying in machine learning: "garbage in, garbage out." In deep learning, this principle is amplified because neural networks are extraordinarily sensitive to the quality, scale, and distribution of their input data. Proper preprocessing is not optional polish — it is often the difference between a model that converges in 10 epochs and one that never converges at all. This guide covers the essential preprocessing techniques you will use in virtually every deep learning project.
Why Preprocessing Matters
Consider a neural network with two input features: one ranging from 0 to 1 (say, a normalized ratio) and another ranging from 10,000 to 1,000,000 (say, income in dollars). Without preprocessing, the gradient updates will be dominated by the large-scale feature. The loss landscape becomes elongated and narrow — gradient descent takes tiny zigzagging steps instead of moving directly toward the minimum. Proper normalization makes the loss landscape more spherical, allowing faster and more stable convergence.
Specifically, preprocessing helps because:
- Neural networks use gradient descent, which is sensitive to feature scales
- Proper normalization can speed up training by 10 to 100 times
- Data augmentation acts as a regularizer, preventing overfitting on small datasets
- Cleaning missing or corrupted data prevents the model from learning spurious patterns
- Balanced class distributions prevent the model from becoming biased toward majority classes
Normalization and Standardization
These are the two most common scaling techniques. Understanding when to use each is critical.
Min-Max Normalization scales every feature to the range [0, 1]. It preserves the shape of the original distribution but is sensitive to outliers — a single extreme value can compress all other values into a tiny range.
Z-Score Standardization transforms data to have zero mean and unit variance. It is more robust to outliers and is the preferred choice when your data approximates a Gaussian distribution.
A critical rule: always compute normalization statistics (mean, std, min, max) on the training set only, then apply those same values to validation and test sets. If you compute statistics on the entire dataset, you leak information from the test set into your model — a subtle but common mistake.
Handling Missing Data
Real-world datasets are messy. Sensors fail, users skip form fields, and records get corrupted. You have several strategies:
For deep learning specifically, you can also learn to handle missing data by using a binary mask as an additional input feature — the network learns to adjust its predictions based on what data is available.
Data Augmentation
Data augmentation artificially increases the size and diversity of your training set by applying random transformations to existing samples. It is one of the most effective regularization techniques in deep learning — essentially free additional data.
The key principle: augmentation should produce images that could plausibly appear in the real world. For medical X-rays, horizontal flips make sense (left and right lungs are similar), but vertical flips do not (upside-down X-rays are not realistic). Always think about domain-appropriate augmentations.
For text data, augmentation techniques include synonym replacement, random insertion, random swap, and back-translation (translating to another language and back). For tabular data, techniques like SMOTE (Synthetic Minority Over-sampling Technique) generate synthetic examples.
Creating Efficient Data Pipelines
In practice, data loading is often the bottleneck. A well-designed pipeline loads and preprocesses data in parallel while the GPU trains on the current batch.
The num_workers parameter spawns separate processes that load and preprocess the next batches while the GPU is busy training. Setting pin_memory=True allocates data in non-pageable RAM, which enables asynchronous GPU transfers — the CPU does not block while data moves to the GPU.
Handling Imbalanced Datasets
Many real-world problems have imbalanced classes — fraud detection (99.9% legitimate), medical diagnosis (rare diseases), defect detection. A naive model will simply predict the majority class and achieve high accuracy while being completely useless.
Train/Validation/Test Split
A proper split is foundational. Never evaluate on data the model has seen during training.
from sklearn.model_selection import train_test_split
# Standard split: 70% train, 15% validation, 15% test
X_train, X_temp, y_train, y_temp = train_test_split(
X, y, test_size=0.3, random_state=42, stratify=y
)
X_val, X_test, y_val, y_test = train_test_split(
X_temp, y_temp, test_size=0.5, random_state=42, stratify=y_temp
)
# 'stratify=y' ensures each split has the same class proportions as the original
print(f"Train: {len(X_train)}, Val: {len(X_val)}, Test: {len(X_test)}")Interview Questions
- Why do we normalize input data before feeding it to a neural network?
Normalization ensures all features are on similar scales, preventing features with large ranges from dominating gradient updates. It makes the loss landscape more isotropic, enabling faster convergence and more stable training.
- What is the difference between normalization and standardization?
Normalization (min-max) scales to [0,1] range; standardization (z-score) transforms to zero mean and unit variance. Standardization is preferred when data has outliers or when the distribution is approximately Gaussian.
- Why do we augment training data but not test data?
Augmentation artificially increases training variety to prevent overfitting and improve generalization. Test data should reflect real-world conditions without artificial modification — we want to measure true performance.
- How does pin_memory help in PyTorch DataLoaders?
It pre-allocates data in page-locked (pinned) memory, enabling asynchronous CPU-to-GPU data transfer. Without it, the transfer requires an extra copy step through pageable memory.
- Why must normalization statistics come from the training set only?
Using test set statistics introduces data leakage — the model indirectly gains information about the test distribution, leading to overly optimistic performance estimates that do not generalize.
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for Data Preprocessing for Deep Learning.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this Deep Learning topic.
Search Terms
deep-learning, deep learning, deep, learning, prerequisites, data, preprocessing, data preprocessing for deep learning
Related Deep Learning Topics