Principal Component Analysis (PCA) is a tool that is used to reduce the dimensionality of data while retaining as much of the information as possible. PCA is usually applied on a dataset containing features in a large number to extract a smaller number of useful features that capture most of the variance in the original dataset.
Here's how to perform PCA in MATLAB:
Assume you have a dataset 'X' of n observations on p variables, where each row contains an observation and each column contains a variable.
zscore
function to standardize your dataset.main.m21 chars2 lines
main.m21 chars2 lines
eig
function to obtain the eigenvectors and eigenvalues of the covariance matrix.main.m48 chars2 lines
The eigenvectors are the principal components of the dataset, and the eigenvalues measure the amount of variance in the data explained by each principal component.
main.m91 chars3 lines
main.m24 chars2 lines
Now 'pc' matrix contains the principal components.
That's it! You have successfully performed PCA on your dataset using MATLAB.
gistlibby LogSnag