Effacer les filtres
Effacer les filtres

After PCA, ALS method, use coefficients to reproduce decomposition

4 vues (au cours des 30 derniers jours)
Joshua Diamond
Joshua Diamond le 19 Juil 2022
I have a matrix A with 100 rows (trials) and 64 columns (variables). This matrix contains NaN values.
I am using the syntax:
[coeff,score] = pca(A,'algorithm','als');
This produces coeff, which is 64 x 64, and score, which is 100 x 64.
I then have a second matrix, B, which is 100 x 64. B also contains NaNs.
Usually, I could do:
score_b = B * coeff
However, this just produces a matrix full of NaNs. It doesn't work because of the NaN values in B. How do I recreate the effect of doing PCA, ALS algorithm, on B?
For instance, I can do as follows, but it doesn't seem as elegant.
[~,score] = pca([A;B],'algorithm','als')
score_b = score(101:200,:)

Réponses (1)

Balavignesh
Balavignesh le 4 Oct 2023
Hi Joshua,
As per my understanding, you would like to find 'score_b' for a matrix 'B' by using 'PCA' score of matrix 'A', which has 'NaN' values.
However, applying the 'PCA' to matrix 'A' resulted in a 'score' and 'coeff' which are 'NaN'.
I would suggest you apply 'PCA' to some legitimate dataset to get valid results.
Here is an example code that could help you understand this:
% This is an example dataset. Input your own dataset
load hald.mat
ingredients
ingredients = 13×4
7 26 6 60 1 29 15 52 11 56 8 20 11 31 8 47 7 52 6 33 11 55 9 22 3 71 17 6 1 31 22 44 2 54 18 22 21 47 4 26
[coeff , score] = pca(ingredients,'Algorithm','als')
coeff = 4×4
-0.0678 -0.6460 0.5673 0.5062 -0.6785 -0.0200 -0.5440 0.4933 0.0290 0.7553 0.4036 0.5156 0.7309 -0.1085 -0.4684 0.4844
score = 13×4
36.8218 -6.8709 -4.5909 0.3967 29.6073 4.6109 -2.2476 -0.3958 -12.9818 -4.2049 0.9022 -1.1261 23.7147 -6.6341 1.8547 -0.3786 -0.5532 -4.4617 -6.0874 0.1424 -10.8125 -3.6466 0.9130 -0.1350 -32.5882 8.9798 -1.6063 0.0818 22.6064 10.7259 3.2365 0.3243 -9.2626 8.9854 -0.0169 -0.5437 -3.2840 -14.1573 7.0465 0.3405
Please refer to the following documentation links to have more information on:
Hope that helps!
Balavignesh

Community Treasure Hunt

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

Start Hunting!

Translated by