# PCA calculation for classification?

2 views (last 30 days)
Tanya on 5 May 2014
Edited: Image Analyst on 13 Jul 2018
To do PCA, we have to compute the covariance matrix from our input data and then eigen decomposition is performed in that covariance matrix.
And to get the covariance matrix, we have to calculate the mean and then substract it with our data (data in matrix). But the problem is that Im going to perform PCA for classification.
And Im confused about how to compute the mean (it must be mean computed in row (consider for the class) / column (consider for the features))?
As in my case, here is the format of my *Feature Matrix*:
Class1: feat1 feat2 feat3...featn
Class2: feat1 feat2 feat3...featn
Class3: feat1 feat2 feat3...featn
Class4: feat1 feat2 feat3...featn
Class5: feat1 feat2 feat3...featn
.
.
.
ClassN: feat1 feat2 feat3...featn
What I have done is
mean (perclass or rows)
so I have ( *Mean Matrix* )
Mean_Class1
Mean_Class2
Mean_Class3
Mean_Class4
Mean_Class5
.
.
.
Mean_ClassN
And then I Substract the data in my *Feature Matrix* with those mean. So it becomes (*Substract Matrix*):
Class1: feat1-Mean_Class1 feat2-Mean_Class2 feat3-Mean_Class3...featn-Mean_ClassN
Class2: feat1-Mean_Class1 feat2-Mean_Class2 feat3-Mean_Class3...featn-Mean_ClassN
Class3: feat1-Mean_Class1 feat2-Mean_Class2 feat3-Mean_Class3...featn-Mean_ClassN
Class4: feat1-Mean_Class1 feat2-Mean_Class2 feat3-Mean_Class3...featn-Mean_ClassN
Class5: feat1-Mean_Class1 feat2-Mean_Class2 feat3-Mean_Class3...featn-Mean_ClassN
.
.
.
ClassN: feat1-Mean_Class1 feat2-Mean_Class2 feat3-Mean_Class3...featn-Mean_ClassN
Next is the *Covariance Matrix*:
(Substract Matrix)*(Substract Matrix)^T
The Principal components are extracted from this Covariance Matrix by using eigs [Vectors,Values] = eigs(CovarianceMatrix);
And for dimensionality reduction, I have to project those data after substract with its mean onto the extracted eigen vectors.
And then to project it:
Substract Matrix * Vectors
1. Are those right? Or there are some mistakes concept?
2. Or I have to compute the mean for each column (consider the Features number)?
3. And for projecting onto the new space, Is that right that I have to substract the data in the matrix with its mean (mean calculated for each row)?
Sorry If this is kind of stupid question, but I really need to confirm the true concept..
Hope someone will kindly answer my this question

jin li on 13 Jul 2018
Edited: Image Analyst on 13 Jul 2018

It is not correct.

How PCA Recognizes Faces - Algorithm In Simple Steps