Finding a zero meaned matrix vertically and horizontally.

11 ビュー (過去 30 日間)
Aldo Andre
Aldo Andre 2022 年 2 月 11 日
編集済み: John D'Errico 2022 年 2 月 11 日
I am trying to understand the first principles of PCA and was set with an exercise that requires me to create a zero meaned matrix in the direction of the features (columns) and variables (rows).For example,for meaning rows,I just need to calculate each rows mean and subtract it in every single elements in the row.However I also need the column mean to be zero simultanously.How can I achieve this ? Applying the same method for columns then rows does not work as it shifts the rows means after they have been zeroed.

採用された回答

John D'Errico
John D'Errico 2022 年 2 月 11 日
編集済み: John D'Errico 2022 年 2 月 11 日
If you are writing a PCA code for yourself, then yes, you want to mean subtract the array. (If you are just going to use the existing PCA tool, then no, there is no need to mean subtract the data.) But only along one of the dimensions, the rows. For example, I've attached the famous iris data set to this answer so that we can use it in an example.
load irisdata
whos
Name Size Bytes Class Attributes ans 1x37 74 char irisdata 150x4 4800 double irisnames 150x1 19600 cell
irismean = mean(irisdata,1)
irismean = 1×4
5.8433 3.0540 3.7587 1.1987
So every column mean has been computed.
irissub = irisdata - irismean; % the mean subtracted array. So each column has had the mean of that column subtracted off.
I think you may have been confused, because here I am talking about rows and columns at once. You compute the mean of the columns, and the result is naturally a row vector. Now subtract off that row of means, from EVERY row in the matrix. I did that in computing irissub.
However, you do not need both the row AND column means to be simultaneously zero to use PCA. Are you saying that you were told to do that? I think you were mistaken. Now you can use SVD to do the heavy lifting.
[U,S,V] = svd(irissub,0);
diag(S)
ans = 4×1
25.0899 6.0079 3.4205 1.8785
V
V = 4×4
0.3616 -0.6565 0.5810 0.3173 -0.0823 -0.7297 -0.5964 -0.3241 0.8566 0.1758 -0.0725 -0.4797 0.3588 0.0747 -0.5491 0.7511
I'll let you go from there, since it appears you must be wanting to write the PCA yourself.

その他の回答 (1 件)

Image Analyst
Image Analyst 2022 年 2 月 11 日
Not sure you need to do that. The documentation for pca() says "By default, pca centers the data and uses the singular value decomposition (SVD) algorithm." so it's done internally for you.

カテゴリ

Help Center および File ExchangeDimensionality Reduction and Feature Extraction についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by