6
$\begingroup$

I have a list "xlsf" with 6 columns and 1200 rows for PCA analysis. The PrincipalComponents[xlsf] gives the following:

"The principal components of matrix are linear transformations of the original columns into uncorrelated columns arranged in order of decreasing variance"

How do I obtain the transformations performed on columns by Mathematica?

$\endgroup$
  • 3
    $\begingroup$ Use SingularValueDecomposition. $\endgroup$ – Szabolcs Jun 17 '14 at 16:02
  • 2
    $\begingroup$ Or KarhunenLoeveDecomposition $\endgroup$ – Oleksandr R. Jun 17 '14 at 18:59
10
$\begingroup$

PrincipalComponents is based on SingularValueDecomposition. Below I'll show what it does:

This is some sample data from the docs:

data = {{13.2, 200, 58, 21.2}, {10, 263, 48, 44.5}, {8.1, 294, 80, 
    31}, {8.8, 190, 50, 19.5}, {9, 276, 91, 40.6}, {7.9, 204, 78, 
    38.7}, {3.3, 110, 77, 11.1}, {5.9, 238, 72, 15.8}, {15.4, 335, 
    80, 31.9}, {17.4, 211, 60, 25.8}};

Let's centre it first:

data2 = # - Mean[data] & /@ data;

Then compute the SVD of the centred data:

{u, s, v} = SingularValueDecomposition[data2];

Now Transpose[v] is the rotation that PrincipalComponents applies to each row.

$\endgroup$
  • $\begingroup$ what happens if I do not center the data? $\endgroup$ – denfromufa Jun 17 '14 at 21:49
  • 1
    $\begingroup$ @denfromufa Do you understand the mathematics behind PCA? $\endgroup$ – Szabolcs Jun 17 '14 at 21:55
  • $\begingroup$ now I understand that PCA can be obtained by doing SVD to centralized data: math.stackexchange.com/questions/3869/… $\endgroup$ – denfromufa Jun 18 '14 at 22:46
  • $\begingroup$ I'm confused by your last statement. Using your variable names, the PCA-transformed data will then be obtained as data2 . v. Why do you refer to Transpose[v] as the rotation being applied? $\endgroup$ – MarcoB May 28 '15 at 7:21
  • $\begingroup$ In Mathematica's Implement, PrincipleCompoments seems a bit from the SVD, use something like eigenSystems for Covariance matrix, because the SVD route gives the same result by DimensionReduce by LSA not the same with PrincipleCompoments $\endgroup$ – HyperGroups Aug 21 '17 at 3:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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