python - sklearn PCA not working -


i have been playing around sklearn pca , behaving oddly.

from sklearn.decomposition import pca import numpy np identity = np.identity(10) pca = pca(n_components=10) augmented_identity = pca.fit_transform(identity) np.linalg.norm(identity - augmented_identity)  4.5997749080745738 

note set number of dimensions 10. shouldn't norm 0?

any insight why not appreciated.

although pca computes orthogonal components based on covariance matrix, input pca in sklearn data matrix instead of covairance/correlation matrix.

import numpy np sklearn.decomposition import pca  # gaussian random variable, 10-dimension, identity cov mat x = np.random.randn(100000, 10)    pca = pca(n_components=10) x_transformed = pca.fit_transform(x)  np.linalg.norm(np.cov(x.t) - np.cov(x_transformed.t))  out[219]: 0.044691263454134933 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -