Reputation: 6290
I'm totally confused regarding PCA. I have a 4D image of size 90x60x12x350. That means that each voxel is a vector of size 350 (time series).
Now I divide the 3D image (90x60x12) into cubes. So let's say a cube contains n voxels, so I have n vectors of size 350. I want to reduce this n
vectors to only one vector and then calculate the correlations between all vectors of all cubes.
So for a cube I can construct the matrix M
where I just put each voxel after each other, i.e. M = [v1 v2 v3 ... vn]
and each v
is of size 350.
Now I can apply PCA in Matlab by using [coeff, score, latent, ~, explained] = pca(M);
and taking the first component. And now my confusion begins.
Should I transpose the matrix M
, i.e. PCA(M')
?
Should I take the first column of coeff or of score?
This third question is now a bit unrelated. Let's assume we have a
matrix A = rand(30,100)
where the rows are the datapoints and the
columns are the features. Now I want to reduce the dimensionality of
the feature vectors but keeping all data points.
How can I do this with PCA?
When I do [coeff, score, latent, ~, explained] = pca(M);
then
coeff is of dimension 100x29 and score is of size 30x29. I'm
totally confused.
Upvotes: 1
Views: 5884
Reputation: 783
I disagree with the answer above.
[coeff,score]=pca(A)
where A has rows as observations and column as features.
If A has 3 featuers and >3 observations (Let's say 100) and you want the "feature" of 2 dimensions, say matrix B (the size of B is 100X2). What you should do is:
B = score(:,1:2);
Upvotes: 0
Reputation: 67847
Yes, according to the pca
help, "Rows of X correspond to observations and columns to variables."
score
just tells you the representation of M
in the principal component space. You want the first column of coeff
.
numberOfDimensions = 5;
coeff = pca(A);
reducedDimension = coeff(:,1:numberOfDimensions);
reducedData = A * reducedDimension;
Upvotes: 5