5

I'm trying to reduce dimension of data set by computing what can be the best n_components using truncated SVD but its taking lot of time.

from sklearn.decomposition import TruncatedSVD
pca = TruncatedSVD()
pca.n_components = 10048
pca_data = pca.fit_transform(X_tr)
percentage_var_explained = pca.explained_variance_ / 
np.sum(pca.explained_variance_);cum_var_explained = np.cumsum(percentage_var_explained)
desertnaut
  • 57,590
  • 26
  • 140
  • 166

1 Answers1

-1

You could instead use the following (if we want to retain 95% of variance in data, change number as you see fit):

from sklearn.decomposition import PCA
pca = PCA(n_components = 0.95)
reduced = pca.fit_transform(X)

If I'm missing the point, let me know where I'm not connecting, I'll try to help.

TJ15
  • 72
  • 1
  • 11