Top 10 Things to Know About Deep Learning

Standardizing a Dataset: Achieving Zero Mean and Unit Variance

Introduction

In the world of data science and machine learning, datasets are often represented in the form of a matrix XXX, where rows represent observations and columns represent features. Before applying most algorithms, it is important to bring the features on the same scale. This is because raw data may contain variables with very different ranges: one feature may represent income in thousands, while another may represent height in centimeters. If not treated, such differences can dominate the analysis. To overcome this, we perform standardization—a transformation of the data so that each feature has a mean of zero and a variance of one. This process ensures that all features contribute equally to model training.

Master Python: 600+ Real Coding Interview Questions
Master Python: 600+ Real Coding Interview Questions

How to Transform Matrix XXX

To standardize each feature, we need to transform the matrix XXX in a systematic way:

  1. Compute the Mean of Each Feature
    For every column (feature) in XXX, calculate its mean value. Let’s denote the mean of the jthj^{th}jth feature as μj\mu_jμj​.
  2. Compute the Standard Deviation of Each Feature
    For the same feature, calculate its standard deviation, denoted as σj\sigma_jσj​. This measures the spread of the feature values.
  3. Apply the Standardization Formula
    Each entry in the dataset is then transformed using the following formula: Xij′=Xij−μjσjX’_{ij} = \frac{X_{ij} – \mu_j}{\sigma_j}Xij′​=σj​Xij​−μj​​ Here, XijX_{ij}Xij​ is the value of the ithi^{th}ith observation in the jthj^{th}jth feature. Subtracting the mean centers the data around zero, while dividing by the standard deviation scales it so that the variance becomes one.
Machine Learning & Data Science 600+ Real Interview Questions
Machine Learning & Data Science 600 Real Interview Questions

4. Resulting Matrix
The resulting matrix X′X’X′ will have each feature column with a mean of zero and a standard deviation of one. This matrix is now ready for most algorithms, such as linear regression, principal component analysis, or clustering.


    Why Not Multiply by Its Transpose?

    It might seem tempting to multiply XXX by its transpose, X⋅XTX \cdot X^TX⋅XT, as a way to “adjust” the data. However, this operation does something entirely different—it creates a Gram matrix that measures inner products between rows (observations). While useful in some contexts such as kernel methods, it does not standardize the data. Standardization is always a column-wise operation, not a matrix multiplication. Thus, the correct approach is to subtract the mean and divide by the standard deviation for each feature.

    Master LLM and Gen AI: 600+ Real Interview Questions
    Master LLM and Gen AI: 600+ Real Interview Questions

    Conclusion

    Standardization is a vital preprocessing step in data science. By transforming each feature to have zero mean and unit variance, we ensure fairness across variables and improve the performance of many machine learning algorithms. The process is straightforward: subtract the column mean and divide by the column’s standard deviation. While matrix multiplications such as X⋅XTX \cdot X^TX⋅XT serve other purposes in linear algebra, they do not achieve standardization. Therefore, the proper transformation of matrix XXX relies on the formula (Xij−μj)/σj(X_{ij} – \mu_j) / \sigma_j(Xij​−μj​)/σj​, which guarantees balanced features and a dataset ready for further analysis.

    Leave a Reply