8
$\begingroup$

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?

$\endgroup$
0

1 Answer 1

8
$\begingroup$

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$.

$\endgroup$
3
  • 1
    $\begingroup$ +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. $\endgroup$
    – Sycorax
    Commented May 3, 2016 at 15:42
  • $\begingroup$ Ah, so you could have self-answered it! $\endgroup$
    – amoeba
    Commented May 3, 2016 at 15:44
  • 1
    $\begingroup$ 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. $\endgroup$
    – meh
    Commented May 3, 2016 at 19:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.