Reducing dimensionality of features with PCA
5 ビュー (過去 30 日間)
古いコメントを表示
I'm totally confused regarding PCA. I have a 4D image of size 90 x 60 x 12 x 350. That means that each voxel is a vector of size 350 (time series).
Now I divide the 3D image (90 x 60 x 12) 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 100 x 29 and score is of size 30 x 29. I'm totally confused.
0 件のコメント
回答 (3 件)
Matlaber
2019 年 2 月 19 日
Is there any setting input arguement of
coeff = pca(X)
coeff = pca(X,Name,Value)
[coeff,score,latent] = pca(___)
[coeff,score,latent,tsquared] = pca(___)
[coeff,score,latent,tsquared,explained,mu] = pca(___)
for reducing a matrix of (400 * 40) to (400 * 20) ?
Thanks
Alfonso Nieto-Castanon
2015 年 6 月 5 日
If you use:
[coeff,score] = pca(M);
Comp_PCA1 = score(:,1);
where M is a (300 by n) matrix of voxel timeseries, and you keep the first column of the resulting matrix score, that will have the (300 by 1) timeseries/vector of component scores most representative of the timeseries variance within your cube.
Note that pca(X) first subtracts the mean effect mean(X,1) from X and then performs SVD on the residuals to decompose the resulting covariance in its principal components. You do not want to use pca(M') because then you would be disregarding the average timeseries across all your voxels within each cube (which often contains useful information). Using pca(M) will instead disregard the average signal across all your timepoints for each voxel, which is fine if you are planning to use this for correlation analyses (since the correlations are invariant to the average value of the timeseries)
3 件のコメント
Alfonso Nieto-Castanon
2015 年 6 月 5 日
Regarding normalization of your features, that depends on the classifier that you are planning to use. Many classifiers (e.g. random forest, SVM's) will be invariant to this form of scaling, while others (e.g. logistic regression, gaussian mixture models) will not.
Regarding your the second question, assumming that your feature vectors are mean-centered, the two methods (keeping the first 10 columns of score or multiplying A by the first 10 columns of coeff) are exactly equivalent.
Last, if you are planning to use all this in a machine learning context, please be aware that you need to define your features consistently across your training and validation datasets. That typically means that you do not want to apply PCA on the validation dataset but rather store the coeff matrices computed from the training set and use those to project the validation data. This is particularly important when using PCA since the resulting coefficients/scores are scale/reflection invariant (e.g. you could arbitrarily get -coeff and -score instead of coeff and score as your coefficients/scores resulting from PCA)
参考
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!