scikit learn - Python | SKlearn | PCA -


edit: spotting typo, should 60*50, have corrected same in question.

i stuck on following problem, after performing pca on matrix 60 observations , 50 variables when checked shape of pca component comes out 50*50. whereas think should 60*50. same checked in r, comes out be, per understanding, 60*50. please let me know if doing wrong. pfb code:

import numpy np arr=np.random.randn(20*3*50) numpy import * arr = (arr - mean(arr, axis=0)) / std(arr, axis=0) arr=arr.reshape(60,50) arr.shape #output: (60, 50)  arr[1:20, 2] = 1 arr[21:40, 1] = 2 arr[21:40, 2] = 2 arr[41:60, 1] = 1 arr.shape #output: (60, 50)  sklearn.decomposition import pca pca = pca() x_train_pca = pca.fit_transform(arr) pca.components_.shape #output: (50, 50) 

look @ pca class in scikit-learn. tells that:

...if n_components not set components kept:

n_components == min(n_samples, n_features)

as far pca.components_ returns array of shape (n_components, n_features), there no confusion.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -