PCA Plot Script/Synthax

18 次查看(过去 30 天)
FkBang
FkBang 2020-10-1
回答: Gaurav Garg 2020-10-14
Hi everyone. Sorry but I am very new to Matlab. The data I am working with has 10 variables and 31 observations. The 11th column is one of two categories to which each of these observations belong. I am using PCA to determine which of these 10 variables are most influential (or responsible for the most variance). I would like to get a 3D plot of the first 3 Principal components. Please, see below my script for this task.
[coeff,score,latent,tsquared,explained,mu] = pca(Values(:,1:10), 'NumComponents', 10)
y = Values(:,11);
scatter3(Values(:,1),Values(:,2),Values(:,3), 20, y, 'filled')
colormap(jet);
axis equal
xlabel('1st Principal Component')
ylabel('2nd Principal Component')
zlabel('3rd Principal Component')
Note: I imported the observations from a csv file as “Values” (49x11) and the variables as “Parameters” (1x11).
Below is what the above script produces:
I was hoping to get the points for the various variables in the plot in different colours to be able to tell which variable is where. At the moment it’s only the two categories that have been colour coded and not the variables. I hope there is a way to get these variables colour coded.I would appreciate it very much if I could get the correct script for this. Thanks a lot in advance.

采纳的回答

Gaurav Garg
Gaurav Garg 2020-10-14
Hi,
As can be seen in
scatter3(Values(:,1),Values(:,2),Values(:,3), 20, y, 'filled')
You are trying to plot y, which represents the categories of the observations.
Insted of plotting y, you will be needing to plot either of the following variables -
coeff,score,latent,tsquared,explained,mu

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Dimensionality 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