フィルターのクリア

Generating a plot of showing points directed towards PC1

7 ビュー (過去 30 日間)
Stephen Hummel
Stephen Hummel 2021 年 6 月 21 日
回答済み: Yash Sharma 2024 年 5 月 22 日
I have a data set (attached) where the columns are the ID, X, Y, and Z coordinate values. I have run the principal component function (pca) on the data. I want to plot the points along PC1 only and show the eigen vectors of each point as arrows directed towards the PC1 line. Can anyone recommend the best way to generate a plot like this? Do I need to normalize the eigen values? Is it better to run signle value decomposition (SVD) instead of PCA?
[coeff,score,latent,tsquared,explained,mu] = pca(Data(:,[2 3 4]))

回答 (1 件)

Yash Sharma
Yash Sharma 2024 年 5 月 22 日
Hi Stephen
To plot your data points along the first principal component (PC1) and show eigenvectors as arrows directed towards the PC1 line, follow these steps:
  1. Plot Points on PC1: Use the score output from PCA, which contains the coordinates in the principal component space. The first column is your projection onto PC1.
  2. Visualize Eigenvectors: The coeff matrix contains eigenvectors. Plot these as arrows using the mean of your data as the origin. Normalize these vectors if you want to emphasize direction over magnitude.
  3. PCA vs. SVD: For your purpose, PCA is sufficient. It provides the principal components and their eigenvectors, which is what you need for visualization.
% Assuming PCA has been run and you have coeff, score, and mu
figure;
plot(score(:,1), zeros(size(score(:,1))), 'bo'); % Points on PC1
hold on;
% Eigenvectors as arrows from data mean
quiver(mu(1)*ones(1,3), mu(2)*ones(1,3), coeff(1,:), coeff(2,:), 0.5, 'k');
xlabel('PC1');
title('Projection onto PC1 with Eigenvectors');
axis equal;
grid on;
hold off;
This code plots data points along PC1 and draws eigenvectors as arrows. Adjust the quiver function's scaling factor as needed for clear visualization.

カテゴリ

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