- If each row or column of your input matrix represents an independent measurement, remove all rows (or columns) that contain any NaN values.
- Set all NaN values to zero, or to the mean (or median) of all values in the matrix. Possibly, it would be better to set them to the mean of the row or column that they are in, if these each represent one type of measurement.
- Take a look at the fillmissing function, perhaps one of the options there would be suitable for replacing the NaN values in your input data.
Error in computing pca with nan values
12 views (last 30 days)
Show older comments
Hello,
I used pca. After computing the covariance matrix, I saw the NaN values in it. When I want to calculate the eigenvalues and eigenvectores, it gives an error.
Error using eig
Input matrix contains NaN or Inf.
Error in TrainData (line 113)
[V,LAMBDA]=eig(C);
Please guide me
thank you
1 Comment
Christine Tobler
on 28 Oct 2019
PCA is based on SVD or EIG, and these functions do not support NaN inputs. This is because there is no simple, unique way to ignore NaN values when computing these function.
Some ideas:
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!