How to get my desired dimension using pca in MATLAB?

조회 수: 2 (최근 30일)
Sunil Kumar
Sunil Kumar 2020년 2월 29일
답변: Aditya 2025년 3월 25일
My matrix is of dimension 101x64. After applying PCA the matrix got reduced to 64x64. I want my reduced matrix to be of form 1xN. How can i do this?
  댓글 수: 1
nathan welch
nathan welch 2020년 3월 6일
I don't think Principle Component Analysis (PCA) can reduce your matrix to a row vector.
If you're using it in a similar manner to Singular Value Decomposition (SVD) and factorizing your rectangular matrix into the form:
Then the information you problem want is the scalar data from the diagonal matrix
If you can get hold of this then you can extract the diagonal elements using: s = diag(Sigma)'
This should then give you a 1x64 set of values.

댓글을 달려면 로그인하십시오.

답변 (1개)

Aditya
Aditya 2025년 3월 25일
Hi Sunil,
To reduce your matrix to a form of (1 \times N) using PCA, you'll need to perform a few steps. Typically, PCA reduces the dimensionality by projecting the data onto a smaller number of principal components. Here's a general approach to achieve a (1 \times N) matrix:
% Assume X is your original 101x64 data matrix
X = rand(101, 64); % Example data
% Center the data
X_centered = X - mean(X);
% Compute the covariance matrix
covMatrix = cov(X_centered);
% Perform eigen decomposition
[eigenVectors, eigenValues] = eig(covMatrix);
% Sort eigenvectors by eigenvalues in descending order
[~, sortedIndices] = sort(diag(eigenValues), 'descend');
eigenVectors = eigenVectors(:, sortedIndices);
% Project the data onto the principal components
% Here, we project onto all 64 components (can be reduced as needed)
projectedData = X_centered * eigenVectors;
% Flatten the projected data to form a 1xN vector
% Here, N is 64*64 = 4096 for full projection
flattenedData = reshape(projectedData', 1, []);
% If you want fewer components, adjust the number of columns in eigenVectors
% For example, to keep only the first 10 components:
numComponents = 10;
projectedDataReduced = X_centered * eigenVectors(:, 1:numComponents);
flattenedDataReduced = reshape(projectedDataReduced', 1, []);

카테고리

Help CenterFile Exchange에서 Dimensionality Reduction and Feature Extraction에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by