How can I plot direction of principal components in PCA
17 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
farshad jahangiri
le 27 Sep 2022
Commenté : farshad jahangiri
le 27 Sep 2022
Hi I want to plot principal component's direction like this picture in 2D space. How can I do it ?![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1137305/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1137305/image.png)
0 commentaires
Réponse acceptée
Chunru
le 27 Sep 2022
x = randn(4, 2);
plot(x(:,1), x(:,2), 'ro', 'DisplayName', 'data'); axis equal; hold on
p = pca(x);
xc = mean(x);
quiver(xc(1), xc(2), p(1, 1), p(2, 1), 'b' , 'DisplayName', 'Principal');
quiver(xc(1), xc(2), -p(1, 1), -p(2, 1), 'b','HandleVisibility','off');
quiver(xc(1), xc(2), p(1, 2), p(2, 2), 'g', 'DisplayName', 'secondary');
quiver(xc(1), xc(2), -p(1, 2), -p(2, 2), 'g','HandleVisibility','off');
legend
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Dimensionality Reduction and Feature Extraction dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!