Feature Manipulation and Normalization
Feature transformations should be selected according to the property that needs to change.
Try it: Feature Scaling: Min-Max and Standardization
How centering, min-max scaling and standardization change each feature's location and range, and why features on very different scales let one feature dominate Euclidean distances — so the nearest neighbour can change once the features are scaled. The scaler's statistics come from the training data and are then applied unchanged to new data.
How it works
- Fit the scaler per feature on the training points: mean (centering), min and max (min-max), or mean and standard deviation (standardization).
- Transform every training point with that feature's formula: x − mean, (x − min)/(max − min) (optionally mapped to [−1, 1]), or (x − mean)/std.
- Apply the same fitted transform to the test point — it may land outside [0, 1]; the scaler is not refitted on new data.
- Measure the Euclidean distance from the test point to every training point in the transformed space and rank them.
- Compare with the raw ranking: without scaling, the feature with the larger numbers dominates; centering alone changes nothing.
Default run (11 steps): 6 training points and one test point (100 sq m, 6 rooms). Area spans 40–180, rooms 1.5–7. Method: standardization, fitted on the training points only. … Nearest neighbour after standardization: p_2 (class B); ranking p_2 < p_4 < p_3 < p_6 < p_1 < p_5. With raw values it would be p_1 (class A) — the large-scale area feature dominated.
Simplified: Two features (area 20–200 sq m, rooms 1–8) and at most 8 training points on a grid; the effect is shown on a 1-nearest-neighbour lookup only. Standard deviation is the population value (ddof = 0) and a zero range or zero spread is replaced by 1, as scikit-learn does.
Loading the simulation…
Choosing the Property to Change
A feature is not always presented in the most useful numerical form. Its values may be shifted away from zero, cover an inconvenient range, contain unusually high or low values, or represent counts whose differences are not equally meaningful. Feature manipulation and normalization provide several ways to change that representation. The central rule is simple: identify the property that needs to change first, then select the transformation that addresses it.
Do not choose a transformation merely because it is familiar. Choose it according to whether the problem concerns location, spread, extreme values, or the meaning of differences across a count scale.
Tracing Location and Spread
Centering, scaling, and standardization all reorganize the numerical position of a feature, but they do different jobs. Centering changes location by subtracting the empirical mean from every value. Scaling changes the range, commonly placing values between 0 and 1 or between −1 and 1. Standardization combines a location adjustment with a variance adjustment: it subtracts the empirical mean and divides by the standard deviation, producing a feature with zero mean and unit variance.
| Transformation | Primary property changed | Typical result |
|---|---|---|
| Centering | Location | The empirical mean becomes zero |
| Scaling | Range | Values are commonly placed between 0 and 1 or between −1 and 1 |
| Standardization | Location and variance | The feature has zero mean and unit variance |
The different jobs performed by location-and-spread transformations
A Small Feature Trace
Selecting a location or spread adjustment
Suppose a generated feature contains values whose average is far from zero, and a separate feature contains values across an inconvenient numerical range. Which transformation matches each problem?
- 1Inspect the first feature
The problem is its location: the values are shifted away from zero. Centering is appropriate because it subtracts the empirical mean from every value.
- 2Inspect the second feature
The problem is its range. Scaling is appropriate because it changes the range, commonly placing values between 0 and 1 or between −1 and 1.
- 3Consider both properties
If both the location and the variance need adjustment, standardization combines subtraction of the empirical mean with division by the standard deviation.
Use centering for a location problem, scaling for a range problem, and standardization when both mean and variance need adjustment.
Reshaping Extreme and Count Values
Clipping, sigmoidal transformation, and logarithmic transformation do not primarily reposition a feature around its mean or place it inside a fixed range. They alter how values and differences are represented, especially when extreme values or unevenly meaningful count differences are a concern.
Clipping limits high or low feature values to a specified range. It directly prevents values beyond that range from remaining as large or small as they originally were.
A sigmoidal transformation is a softer alternative for extreme values. Values close to zero are affected only slightly, while values far from zero behave similarly to clipping.
A logarithmic transformation is especially useful for count features when equal numerical gaps do not carry equal meaning. It compresses the large-count end relative to the small-count end.
Count Features in Context
Why a count may need reshaping
Consider a generated word-count feature. Compare the meaning of moving from zero occurrences to one occurrence with moving from 1000 occurrences to 1001 occurrences.
- 1Compare the numerical gaps
Both changes increase the count by one, but the first change can matter much more than the second.
- 2Identify the mismatch
Equal numerical gaps do not necessarily represent equal importance across the count scale.
- 3Select a transformation
A logarithmic transformation is useful because it compresses the large-count end relative to the small-count end.
For a count feature with unevenly meaningful differences, consider a logarithmic transformation rather than treating every numerical gap as equally important.
What do you think happens?
A feature contains a few unusually high values, and you want a direct limit on how high or low values may be. Which transformation best matches that goal?
Reveal answer
Clipping
Clipping limits high or low feature values to a specified range. A sigmoidal transformation would be a softer alternative when extreme values should be treated less strongly rather than directly limited.
Matching Problems to Transformations
- Use centering when the feature's location, represented by its empirical mean, needs adjustment.
- Use scaling when the feature's range is inconvenient.
- Use standardization when both the empirical mean and variance need adjustment.
- Use clipping when high or low values should be limited to a specified range.
- Use a sigmoidal transformation when extreme values need a softer treatment: values near zero should change little, while far-from-zero values should behave similarly to clipping.
- Use a logarithmic transformation for count features when large-count differences should be compressed relative to small-count differences.
Common Selection Mistakes
Common mistake Treating centering, scaling, and standardization as interchangeable.
What it looks likeChoosing scaling when the real issue is that the empirical mean is shifted away from zero.
Why it failsCentering adjusts location, scaling adjusts range, and standardization adjusts both mean and variance.
Do this insteadName the property that needs to change before choosing the operation.
Common mistake Using a location-and-spread adjustment to solve a value-meaning problem.
What it looks likeStandardizing a count feature when large and small count differences have unequal importance.
Why it failsStandardization changes mean and variance, while a logarithmic transformation reshapes the count scale by compressing the large-count end.
Do this insteadUse a logarithmic transformation when the issue is the relative meaning of differences across a count range.
Common mistake Assuming all extreme-value transformations behave in the same way.
What it looks likeDescribing a sigmoidal transformation as an exact hard limit.
Why it failsClipping directly limits high or low values to a specified range, whereas a sigmoid is a softer alternative: values near zero change little and far-from-zero values behave similarly to clipping.
Do this insteadChoose clipping for a direct limit and a sigmoid for softer treatment of extremes.
Common mistake Applying a transformation without diagnosing the feature.
Why it failsDifferent transformations address different properties, and transformations can also be combined when more than one property needs adjustment.
Do this insteadInspect whether the issue concerns location, range, variance, extreme influence, or unevenly meaningful count differences.
Practice the Selection Rule
For each generated situation, select the transformation that best matches the property needing change: a feature shifted away from zero; a feature covering an inconvenient range; a feature requiring both mean and variance adjustment; a feature with unusually high and low values that must be limited; a feature with extreme values that should be softened rather than directly limited; and a count feature where large-count differences matter less than small-count differences.
Hints
- Separate location and range problems from problems involving extreme-value influence.
- For the two extreme-value cases, distinguish a direct limit from a softer response.
- For the count case, consider whether equal numerical gaps have equal meaning.
- 1Feature transformation is a property-matching task. Centering changes location by subtracting the empirical mean. Scaling changes the range. Standardization adjusts both mean and variance. Clipping directly limits extreme values, while a sigmoidal transformation treats extremes more softly. A logarithmic transformation is useful for count features when the large-count end should be compressed relative to the small-count end. Transformations may be combined, but the desired change should be identified first.
Key Takeaways
- Choose a feature transformation according to the property that needs to change.
- Centering adjusts location, scaling adjusts range, and standardization adjusts both mean and variance.
- Clipping and sigmoidal transformation address extreme values differently: clipping imposes a direct limit, while a sigmoid provides a softer response.
- Logarithmic transformation compresses the large-count end when count differences are not equally meaningful across the scale.
- Transformations can be combined when more than one property needs adjustment.