You are viewing a public preview
Sign in to save your progress, do assignments, join discussions and get feedback.
After this unit you will: be able to apply the two scaling formulas and not confuse them with each other.
Normalization (Min-Max) — brings values into the interval [0, 1]:
x_new = (x_old − x_min) / (x_max − x_min)
Standardization (z-score) — brings them to mean 0 and standard deviation 1:
x_new = (x_old − mean) / std
By the end of this lesson you can:
MinMaxScaler.StandardScaler.Key idea: Many algorithms are sensitive to the scale of features. Normalization squeezes values into [0, 1]; standardization gives them mean 0 and standard deviation 1. They are different transformations, so choose one deliberately and be able to explain why.
Imagine one feature measured in the thousands, such as salary, and another in single digits, such as number of children. Without scaling, an algorithm may treat salary as far more important simply because its numbers are bigger, not because it predicts better. Scaling puts every feature on the same playing field so the algorithm can judge them by their real predictive value.
Normalization rescales a numerical feature into a fixed range, usually 0 to 1:
x_new = (x_old - x_min) / (x_max - x_min)
Subtract the column's minimum, then divide by the range (maximum minus minimum). In the lecture, a grade column runs from 0 to 10:
| Grade | Calculation | Normalized |
|---|---|---|
| 6 | (6 - 0) / (10 - 0) | 0.6 |
| 10 (the maximum) | (10 - 0) / (10 - 0) | 1.0 |
| 0 (the minimum) | (0 - 0) / (10 - 0) | 0.0 |
The minimum always becomes 0 and the maximum always becomes 1.
Standardization does not force a fixed range. It shifts and rescales the data so it has mean 0 and standard deviation 1:
x_new = (x_old - mean) / std
The standard deviation measures how spread out the values are. Values above the mean become positive, values below the mean become negative, and the results are not limited to [0, 1].
| Normalization (Min-Max) | Standardization (z-score) | |
|---|---|---|
| Output | Fixed range, usually [0, 1] | Mean 0, std 1, unbounded |
| Often preferred when | Data does not follow a bell curve, or the algorithm expects a bounded input range | Data roughly follows a bell curve (normal distribution) |
| Outliers | Badly skewed: one extreme min or max squashes the other values together | Handles outliers somewhat better |
| scikit-learn | MinMaxScaler | StandardScaler |
In practice you will often try both and keep the one that gives better model performance for your problem.
Scale the lecture's grade column with both scalers. scikit-learn expects a 2-D input (rows by columns), so the grades are written as a column.
import numpy as np
from sklearn.preprocessing import MinMaxScaler, StandardScaler
grade = np.array([[6], [1], [8], [0], [3], [10], [2]], dtype=float)
normalized = MinMaxScaler().fit_transform(grade).ravel()
standardized = StandardScaler().fit_transform(grade).ravel()
print(normalized)
print(standardized.round(2))
print(round(grade.mean(), 3), round(grade.std(), 3))
Expected output:
[0.6 0.1 0.8 0. 0.3 1. 0.2]
[ 0.49 -0.94 1.06 -1.23 -0.37 1.64 -0.65]
4.286 3.493
The normalized values match the lecture: each grade divided by 10. For standardization the mean is about 4.286 and the standard deviation about 3.493, so a grade of 6 becomes (6 - 4.286) / 3.493 = 0.49, while grades below the mean, such as 1 and 0, become negative.
StandardScaler uses the population standard deviation (np.std), while Series.std() in pandas uses the sample version, so the numbers differ slightly.MinMaxScaler or StandardScaler, and be able to explain your choice.Flashcards · 1.8 Normalizing Numerical Features
8 wordsTransforming numerical features to comparable ranges so no feature dominates just because its numbers are larger.
Rescales values into a fixed range, usually [0, 1], using the column's minimum and maximum.
Rescales values so the feature has mean 0 and standard deviation 1.
A measure of how spread out the values of a feature are around their mean.
scikit-learn transformer that applies Min-Max normalization to each column.
scikit-learn transformer that standardizes each column to mean 0 and standard deviation 1.
The shape of a normal distribution; standardization is often preferred when data roughly follows it.
Min-Max scaling is badly skewed by one extreme value, which squashes the other values together.