Use biplot(): How to plot three different colors after running PCA using only the first 2 principal components

10 views (last 30 days)

Hello,

I am new to Matlab and I do not know the syntax well enough to do this task.

I have a data set and I split it into training and testing data as below:

X = csvread('mydata.csv');
flag = X(:,1);
label = X(:,2);
P = X(:,3:end);
train = X(flag < 5,:);
test = X(flag == 5,:);

Now for the "label", which is the second column of data set X, there are three different values: 0, 8, 9. I want to distinguish between the three classes (0, 8, 9) with a different plot symbol and color.

My research so far lets me believe that biplot() is the right tool in MATLAB to do this, but I am not sure how to what function to call or how to manipulate different parameters in biplot() to help me with this.

Below is what I have got so far:

Zeros = label(label == 0);
Eights = label(label == 8);
Nines = label(label == 9);
[coeff,score,latent] = pca(train);
plot (scores(Zeros), scores(Eights),scores(Nines),'.r','markersize', 20);
hold on
plot (scores(~Zeros), scores(~Eights),scores(~Nines),'^b', 'markersize', 7);
Subscript indices must either be real positive integers or logicals.
% Error in myPCA (line 24)
% plot (scores(Zeros), scores(Eights),scores(Nines),'.r','markersize', 20);
biplot(coeff(:,1:2),'scores',score(:,1:2));
% This works fine, but all of the data points are all red.

Thank you!

Answers (0)

Categories

Find more on Dimensionality Reduction and Feature Extraction in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!