First step of PCA

The first step of PCA is to normaling the data.
In the programming assignment
It does not require to divide the standard deviation after substracting the mean:

X_demeaned = (X - X.mean(axis=0))

While I thought it should have been
X_demeaned = (X - X.mean(axis=0))/X.std(axis=0)

Why is that ?

Hey @mc04xkf,
If we take a close look at the markdown, we will find the following:

Mean normalize the data

In other words, we only have to transform the data so that the mean can be 0. We don’t have to set the variance to 1 in this case. Let us know if this helps.

Cheers,
Elemento

Hi @mc04xkf

I would try to complement the Elemento’s answer and try to answer “why”.

This is true when features have different units (for example “height”, “salary”, etc.). But in our case the word embedding features in essence have the same units.

If we added the column of “salary” to X, then we would definitely have had to standardize the matrix because the variance of “salary” would have been much much higher than in other columns (and the basis for PCA is covariance).

Have you tried it? In cases like these I would encourage to try it yourself :slight_smile: . Here is a fun counter question:
Which of these (in the picture) are:

  • de-meaned = X - X.mean(axis=0)),
  • standardized = (X - X.mean(axis=0)) / X.std(axis=0),
  • not changed =X.

Note the magnitude of x and y axes. Try to reason your guesses before you try yourself :slight_smile: