# what does pc1 and pc2 represent?

33 views (last 30 days)

Show older comments

Hello, I have a plot of pca 3d plot and the axes are pc1, pc2 and pc3. How do i determine what each pc component represents?

Also how can i establish the variance that each pc plot contributes? I attached an example for reference.

How can i determine this?

##### 0 Comments

### Accepted Answer

Image Analyst
on 8 Feb 2023

##### 6 Comments

Image Analyst
on 12 Feb 2023

Edited: Image Analyst
on 12 Feb 2023

Once you know what class numbers are you can take, for example, the mean distance from the centroid. I'm sure you've figured it out by now, but anyway here's how I'd do it. The class assignments (indexes) and centroids are both returned from kmeans. Something like (untested)

numClasses = 3;

[assignedClasses, centroids] = kmeans(xy, numClasses);

for k = 1 : numClasses

% Get points assigned to the k'th class

thisxy = xy(assignedClasses == k, :);

x = thisxy(:, 1);

y = thisxy(:, 2);

% Get distances from every point in this class to the centroid of this class.

distances = sqrt((x - centroids(k, 1)) .^ 2 + (y - centroids(k, 2)) .^ 2);

% Get mean and standard deviation of those distances.

meanDistances(k) = mean(distances);

stDevDistances(k) = std(distances);

end

If you want to reorder the class numbers, see the attached demo.

### More Answers (1)

John D'Errico
on 10 Feb 2023

For example...

load fisheriris

whos

[COEFF, SCORE, LATENT] = pca(meas);

So the first component is huge compared to the others, in terms of the total variance explained. The total variance in that system is:

sum(var(meas))

And the

LATENT

So most of the variability lies in the first component.

But what do the components mean, physically? This is eomthing very difficult to know at times.

COEFF(:,1)

Those coefficients represent the linear combination chosen of the various original variables. But trying to say what the linear combination means can be difficult. A biologist might try to infer some sort of meaning to those various weights. And I suppose you might decide that variables like {sepal length, sepal width, petal length, petal width} might all be related in some way, and in combination might tell you something about the plant. But don't go out of your way to try to assign some meaning here.

##### 3 Comments

Image Analyst
on 10 Feb 2023

John D'Errico
on 10 Feb 2023

### See Also

### Categories

### Community Treasure Hunt

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

Start Hunting!