LoginSignup
2
2

More than 3 years have passed since last update.

pyclustering.xmeansでKeyErrorが出る

Posted at

コード

from pyclustering.cluster.xmeans import (
    xmeans, kmeans_plusplus_initializer
)
from pyclustering.utils import draw_clusters


initial_centers = kmeans_plusplus_initializer(df, 2).initialize()

instances = xmeans(df, initial_centers, ccore=True)
instances.process()

エラー

KeyError: 0

During handling of the above exception, another exception occurred:

KeyError  Traceback (most recent call last)
<ipython-input-117-8ff3c8958745> in <module>
      6 
      7 instances = xmeans(X_trans_facility, initial_centers, ccore=True)
----> 8 instances.process()
      9 
     10 clusters = instances.get_clusters()

解決

pd.DataFrameではなくlistnp.ndarrayを使う。


X = df.values

initial_centers = kmeans_plusplus_initializer(X, 2).initialize()

instances = xmeans(X, initial_centers, ccore=True)
instances.process()

参考

バージョン

Python==3.7.4
pyclustering==0.9.3.1
pandas==1.0.2
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2