erdogant / pca

pca: A Python Package for Principal Component Analysis.
https://erdogant.github.io/pca
MIT License
284 stars 42 forks source link

AttributeError if pca().fit_transform used on list #17

Closed nightvision04 closed 3 years ago

nightvision04 commented 3 years ago

The following case will throw an AttributeError:

from pca import pca
X = [[1,2],
     [2,1],
     [3,3]]

p = pca(n_components=2,normalize=True)
p.fit_transform(X)

328             if verbose>=3: print('[pca] >n_components is set to %d' %(self.n_components))
    329 
--> 330         self.n_feat = np.min([self.n_feat, X.shape[1]])
    331 
    332         if (not self.onehot) and (not self.normalize) and isinstance(X, pd.DataFrame) and (str(X.values.dtype)=='bool'):

AttributeError: 'list' object has no attribute 'shape'

Can we check X's type and convert it to np.ndarray if it is a list?