How to plot PCA?

4 visualizzazioni (ultimi 30 giorni)
Mona Alghamdi
Mona Alghamdi il 11 Mar 2019
Risposto: Purvaja il 4 Feb 2025
Hi,
1- How to plot PCA in bar char ?
2- When I plot the PCA using:
mapcaplot:
mapcaplot(x)
Or
pca function:
[coeff,score,latent,tsquared,explained] = pca(x(:,1:5));
score
latent
coeff
explained
I got the principle components. However, I want to know each principle component with the varible (column) name. So, I can identify which principle component representing the actual varible. E.g: PC1 is corresponding to temperature and PC2 is is corresponding to humidity and so on. Also, I got score, latent, and explained. However, the same problem I want to know which value is corresponding to which varible?

Risposte (1)

Purvaja
Purvaja il 4 Feb 2025
I understand that you want to identify which principal components are influenced by which variables and by what values. Also, you wish to plot those on a bar plot for easier visualization.
I would like to clarify one thing; no principal component is affected by only a single variable but influenced by all the variables. We can see which variable is influencing the most using “explained” or “latent” results returned by the “pca” function in MATLAB.
Where “latent” provides the raw eigenvalues, which are useful for understanding the absolute variance captured by each component.
“Explained" is derived from latent and it represents the percentage of the total variance in the data that is captured by the corresponding principal component.
To get the desired results you can follow the given steps:
  • Perform PCA
[coeff, score, latent, tsquared, explained] = pca(data);
  • Display variance explained by each component
disp('Variance Explained by Each Component:');
explained_column = explained+"%";
explained_table = array2table(explained_column, 'VariableNames', {'Variance_Explained'}, 'RowNames', strcat('PC', string(1:length(explained_column))));
disp(explained_table);
  • Combined bar chart for variable influence on all components
figure;
bar(coeff', 'grouped');
xlabel('Principal Components');
ylabel('Coefficient Value');
title('Variable Influence on Principal Components');
xticklabels(strcat('PC', string(1:size(coeff, 1))));
legend(variable_names, 'Location', 'Best');
grid on;
A. The given result shows us the variance of each principal component.
B. This bar plot gives us an idea about how each variable is influencing each principal component.
For more clarification on the functions used, you can refer to the following resources,
Or you can access release specific documentation using this command in your MATLAB command window:
web(fullfile(docroot, 'stats/pca.html'))
Hope this helps you!!

Categorie

Scopri di più su Dimensionality Reduction and Feature Extraction in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by