Standardization › Limitations and Considerations
Michael BrenndoerferApril 25, 20252 min read
Machine Learning from ScratchAll chapters Part 3 of 9Foundations
Standardization › Limitations and ConsiderationsOne section · Sections in this chapter7 / 10 ↓
Sections in this chapter10
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
When applying standardization, keep in mind several important limitations:
- Sparse data: For sparse matrices, standardizing by subtracting the mean can convert the data into a dense format, which is inefficient and memory-intensive.
- Tip: Use
StandardScaler(with_mean=False)to avoid densifying the matrix.
- Tip: Use
- Outliers: Standardization is sensitive to outliers, as extreme values can disproportionately affect the mean and standard deviation, potentially distorting the mapping.
- Categorical variables: Do not standardize one-hot encoded or ordinal categorical variables, as this can destroy their intended meaning.
- Target variable: In most cases, avoid standardizing the target variable unless there is a specific reason to do so.
Be aware of common pitfalls:
- Data leakage: Fitting the scaler on the entire dataset (including the test set) introduces information from the test data into the training process, leading to overly optimistic performance estimates.
- Best practice: Always fit the scaler only on the training data, then use it to transform both the training and test sets.
- Inconsistent scaling: Using different scalers for training and test data can result in mismatched feature distributions.
- Over-standardization: Standardizing features that are already normalized can be unnecessary or even harmful.
- Categorical confusion: Standardizing categorical variables that should remain discrete can undermine their interpretability and utility.
When to use
with_mean=FalseFor sparse inputs, set StandardScaler(with_mean=False) to avoid densifying the matrix. You typically do not standardize the target y for LASSO unless you have a specific reason to do so.