There is no doubt about the function that comes with MATLAB.
Princomp:principal componet Analysis (PCA).
[Coeff,score,latent,tsquare]=princomp (X);
Parameters:
%%%%%%%%%%%%%%%%%%
INPUT:X is the data: N*p, where n is the number of samples and P represents the feature dimension
%%%%%%%%%%%%%%%%%%
OUTPUT:
Coeff: Covariance p*p, projection matrix
Score: The data after the projection. If the number of Samples <= the feature dimension, there is an interesting
Phenomenon: Score (:, n:p), latent (n:p) are zero. Why is it? Please use a total of two
Data points as an example. That is n=2,p=3; when a projection axis is selected, select a
Orthogonal pumping, found that no matter how to choose, they will overlap after projection, that is, 0.
Latent: After the calculation is not the weight of the principal component normalization. If necessary, use the following code:
Cumsum (latent)./sum (latent);
It is important to note that:
The covariance matrix is calculated from the training sample. If we come up with a test set, we can't go back to
Computes a covariance matrix. Because that would cause the training set and the test set to be projected into different spaces,
The resulting feature space is inconsistent and the trained parameters are meaningless.
Matlab comes with Princomp (PCA dimensionality reduction method)