7

I have collected some data and stored them in an $N\times P$ matrix $A$. Using SVD, we can rotate $A=UDV^T$ into a new basis, also discarding some dimensions: $A\approx U\tilde{D}V^T$, where $\tilde{D}$ is a diagonal matrix of the first $k<P$ singular values, with the remaining diagonal values $0$.

Then I train some model using $U\tilde{D}$ as the source data. Now I have a new set of data $B$ that I want to test the model on. The first step in applying the model is rotating $B$ to correspond to the data $U\tilde{D}$ that I trained the model on. How can I do this?

amoeba
  • 93,463
  • 28
  • 275
  • 317
Sycorax
  • 76,417
  • 20
  • 189
  • 313

1 Answers1

7

What you are doing is essentially PCA, even though you did not use this term. It is exactly PCA if your $X$ is centered; if not, then it is a sort of "uncentered PCA".

In any case, to get from $A$ to $UD$ you need to right-multiply it with $V$: $$AV=UDV^\top V = UD.$$

So to apply the same transformation to $B$, you simply right-multiply it with $V$ too.

If you only need the first $k$ columns, then you right-multiply with $V_k$ which is the matrix of the first $k$ columns of $V$.

amoeba
  • 93,463
  • 28
  • 275
  • 317
  • 1
    +1 Thanks! I know this is a basic question, but I was surprised when searching the archives didn't return any results for this. Hopefully your answer will become yet another of your several canonical contributions to CV. – Sycorax May 03 '16 at 15:42
  • Ah, so you could have self-answered it! – amoeba May 03 '16 at 15:44
  • 1
    The way I always remember it is that X is n by p then V has to be p by p and so V is what has to be applied to the data to transform the variables. – meh May 03 '16 at 19:03