首页 > 解决方案 > 我如何解决我的 Birch Clustering PyPlot 错误问题

问题描述

我对我的数据进行了 Birch 聚类分析。之后,我尝试使用下面的代码来绘制我的分析,然后我得到了这个错误。我该如何解决?谢谢你。

# create scatter plot for samples from each cluster
for cluster in clusters:
# get row indexes for samples with this cluster
    row_ix = where(yhat == cluster)
# create scatter of these samples
    pyplot.scatter(dfAB1[row_ix, 0], dfAB1[row_ix, 1])
# show the plot
    pyplot.show()

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-24-840a4662002f> in <module>
      4     row_ix = where(yhat == cluster)
      5 # create scatter of these samples
----> 6     pyplot.scatter(dfAB1[row_ix, 0], dfAB1[row_ix, 1])

~\anaconda3\lib\site-packages\pandas\core\frame.py in __getitem__(self, key)
   3022             if self.columns.nlevels > 1:
   3023                 return self._getitem_multilevel(key)
-> 3024             indexer = self.columns.get_loc(key)
   3025             if is_integer(indexer):
   3026                 indexer = [indexer]

~\anaconda3\lib\site-packages\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance)
   3078             casted_key = self._maybe_cast_indexer(key)
   3079             try:
-> 3080                 return self._engine.get_loc(casted_key)
   3081             except KeyError as err:
   3082                 raise KeyError(key) from err

pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()

TypeError: '((array([3586, 3591, 3592, ..., 6982, 6983, 6984], dtype=int64),), 0)' is an invalid key

标签: pythoncluster-analysis

解决方案


推荐阅读