Data Preprocessing
Beginner
Z-score Standardization
Beginner
~10 min
code completion
Z-score Standardization
Z-score standardization (also called standard scaling) transforms features to have zero mean and unit variance:
where and .
Unlike min-max normalization, standardization is robust to outliers and is preferred for algorithms that assume normally distributed data (e.g., linear regression, PCA).
Your task:
Implement z_score_standardize(X). Assume the standard deviation is nonzero.
Example Tests
Symmetric array: mean=0, std=2
Input: {"X":[-3,-1,0,1,3]}
Expected: [-1.5,-0.5,0,0.5,1.5]
Sum of output is 0 (zero mean)
Input: {"X":[2,4,6,8,10]}
Expected: 0
3-element array: known z-scores
Input: {"X":[10,20,30]}
Expected: [-1.22474,0,1.22474]