# Principal Components - how to obtain linear transformations?

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?

• Use SingularValueDecomposition. – Szabolcs Jun 17 '14 at 16:02
• Or KarhunenLoeveDecomposition – Oleksandr R. Jun 17 '14 at 18:59

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.

• what happens if I do not center the data? – denfromufa Jun 17 '14 at 21:49
• @denfromufa Do you understand the mathematics behind PCA? – Szabolcs Jun 17 '14 at 21:55
• now I understand that PCA can be obtained by doing SVD to centralized data: math.stackexchange.com/questions/3869/… – denfromufa Jun 18 '14 at 22:46
• 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? – MarcoB May 28 '15 at 7:21
• 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 – HyperGroups Aug 21 '17 at 3:10