PCA values

4 ビュー (過去 30 日間)
Raviteja
Raviteja 2011 年 9 月 17 日
編集済み: Mouse 2021 年 11 月 8 日
I have written following code to learn about PCA.
clear all
clc
load hald
hald=ingredients;
[m n]=size(hald);
mu=mean(hald);
mumat=repmat(mu,[m 1]);
hald_new=hald-mumat;
cov_mat=cov(hald_new);
[EVec EVal]=eig(cov_mat);
[sq iq]=sort(diag(EVal)','descend');
for i=1:length(iq)
EVec_sort(:,i)=EVec(:,iq(i));
end
EVal_sort=sq;
pca_data=EVec_sort'*hald_new';
And also I compared my results with matlab princomp() function. Results are like this..
My result
>> pca_data'
ans =
36.8218 6.8709 -4.5909 0.3967
29.6073 -4.6109 -2.2476 -0.3958
-12.9818 4.2049 0.9022 -1.1261
23.7147 6.6341 1.8547 -0.3786
-0.5532 4.4617 -6.0874 0.1424
-10.8125 3.6466 0.9130 -0.1350
-32.5882 -8.9798 -1.6063 0.0818
22.6064 -10.7259 3.2365 0.3243
-9.2626 -8.9854 -0.0169 -0.5437
-3.2840 14.1573 7.0465 0.3405
9.2200 -12.3861 3.4283 0.4352
-25.5849 2.7817 -0.3867 0.4468
-26.9032 2.9310 -2.4455 0.4116
Matlab result:
>> [pc,score,latent,tsquare] = princomp(ingredients);
>> score
score =
36.8218 -6.8709 -4.5909 0.3967
29.6073 4.6109 -2.2476 -0.3958
-12.9818 -4.2049 0.9022 -1.1261
23.7147 -6.6341 1.8547 -0.3786
-0.5532 -4.4617 -6.0874 0.1424
-10.8125 -3.6466 0.9130 -0.1350
-32.5882 8.9798 -1.6063 0.0818
22.6064 10.7259 3.2365 0.3243
-9.2626 8.9854 -0.0169 -0.5437
-3.2840 -14.1573 7.0465 0.3405
9.2200 12.3861 3.4283 0.4352
-25.5849 -2.7817 -0.3867 0.4468
-26.9032 -2.9310 -2.4455 0.4116
Why the second column giving wrong result (in signs)?
  1 件のコメント
Debarshi Chakraborty
Debarshi Chakraborty 2020 年 1 月 21 日
how to plot this data?

サインインしてコメントする。

採用された回答

Andrew Newell
Andrew Newell 2011 年 9 月 17 日
Eigenvectors are a little arbitrary. If A is a matrix and b is one of its eigenvectors, then so is b multiplied by any scalar. In particular, if
A*b = e*b
for some eigenvalue e, then
A*(-b) = e*(-b).
  3 件のコメント
Andrew Newell
Andrew Newell 2011 年 9 月 17 日
Yes.
Mouse
Mouse 2021 年 11 月 8 日
編集済み: Mouse 2021 年 11 月 8 日
Is "princomp" removed in Version R2021a?
I would say yes, it is removed and replaced by "pca"

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

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