Sklearn PCA功能 - 不可用类型:'切片'

时间:2018-01-24 12:31:55

标签: python machine-learning scikit-learn pca

我的代码的主要目标是通过PCA分解将3D数据帧转换为2D,但无法执行它,我假设问题是返回,但不知道如何纠正它,请查看:

def do_PCA(x, svd_solver):

   from sklearn.decomposition import PCA
   pca = PCA(n_components=2, svd_solver='full')
   pca.fit(x)                 
   PCA(copy=True, iterated_power='auto', n_components=2, random_state=None, 
   svd_solver='full', tol=0.0, whiten=False)
   return x

pca = do_PCA(x, "full")

fig = plt.figure()
ax = fig.add_subplot(111)
ax.set_title('Full PCA')
ax.scatter(pca[:,0], pca[:,1], c='blue', marker='.', alpha=0.75)
plt.show()

我得到的错误:

TypeError    Traceback (most recent call last)

<ipython-input-66-94cd1f5059d5> in <module>()
  3 ax = fig.add_subplot(111)
  4 ax.set_title('Full PCA')
  -> 5 ax.scatter(pca[:,0], pca[:,1], c='blue', marker='.', alpha=0.75)
  6 plt.show()

  TypeError: unhashable type: 'slice'

0 个答案:

没有答案