PCA.m with data containing NaN (ncnancov.m bug ?)
2 views (last 30 days)
Show older comments
I can run the following,
data = randn(2.7E6,79);
[~,score,~,~,explained, ~] = pca(data);
I also have a real data matrix of the same size (79 variables, 2.7E6 observations).
Each row ( i.e. time step) has at least one NaN, in one of the variables. Because of this localSVD.m returns a blank. ie pca.m fails.
I can not replace the NaN with zero as this will change the data (the data is a differenced time series, hence zero means something very different to NaN).
I then try a different approach,
[~,score,~,~,explained, ~] = pca(data,'Algorithm','eig', 'Rows', 'pairwise');
the code fails,
Error using eig
Input to EIG must not contain NaN or Inf.
Error in pca>localEIG (line 441)
[coeff, eigValueDiag] = eig(xCov);
Error in pca (line 308)
[coeff, eigValues] = localEIG(x, vCentered, vRows, vWeights,...
Error in cce_moonShine_L1_PCA (line 28)
[~,score,~,~,explained, ~] = pca(data,'Algorithm','eig', 'Rows', 'pairwise');
I then inspect the cov matrix (79*79)
imagesc(isnan(xCov))
and see that one row/col is NaN. It seems like ncnancov.m is failing as it is outputting with NaN in it?
I also get this when trying,
xCov = nancov(x,'pairwise');
suggestions? How can I carry out PCA on this data?
1 Comment
Stephen23
on 22 Dec 2015
Eric's "Answer" moved here:
Hello? This just happened to me too. Does anyone from MATHWORKS want to reply?
Answers (0)
See Also
Categories
Find more on Dimensionality Reduction and Feature Extraction in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!