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

java - HTTP Status 500 - An exception occurred processing JSP page /second.jsp at line 15 -

SQL Server - MyCTE query based on 24 hour period (next day) -

php - Using str_replace to translate a MySQL Table in html -