【发布时间】:2018-08-27 13:45:45
【问题描述】:
我正在尝试使用 sklearn 在具有 162 列和 69,000 行的数据集上运行 PCA。我不断收到下面的浮动错误消息,我已经检查以确保我只有数字数据。我可能做错了什么?任何帮助将不胜感激。
>>> data = np.loadtxt("PCAdata.txt")
>>> trans = data.transpose()
>>> trans
array([[0., 0., 1., ..., 0., 0., 1.],
[0., 0., 1., ..., 1., 0., 2.],
[0., 0., 1., ..., 0., 0., 1.],
...,
[1., 0., 1., ..., 0., 0., 1.],
[0., 0., 1., ..., 0., 0., 2.],
[0., 0., 1., ..., 0., 0., 2.]])
>>> sscaler = preprocessing.StandardScaler().fit(trans)
>>> sscaler
StandardScaler(copy=True, with_mean=True, with_std=True)
>>> pca = PCA(n_components=2)
>>> pca.fit(sscaler)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\sklearn\decomposition\pca.py", line 329, i
n fit
self._fit(X)
File "C:\Python27\lib\site-packages\sklearn\decomposition\pca.py", line 370, i
n _fit
copy=self.copy)
File "C:\Python27\lib\site-packages\sklearn\utils\validation.py", line 433, in
check_array
array = np.array(array, dtype=dtype, order=order, copy=copy)
TypeError: float() argument must be a string or a number
【问题讨论】:
标签: python-2.7 scikit-learn pca