I get a KeyError in pyclustering.xmeans

code

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()

error

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()

Solution

Use list or np.ndarray instead of pd.DataFrame.


X = df.values

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

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

reference

https://stackoverflow.com/questions/58135808/how-to-fix-an-error-when-trying-to-cluster-2-rows-in-a-csv-file

version

Python==3.7.4
pyclustering==0.9.3.1
pandas==1.0.2

Recommended Posts

I get a KeyError in pyclustering.xmeans
I get a UnicodeDecodeError in mecab-python3
When I get a chromedriver error in Selenium
I get a java.util.regex.PatternSyntaxException when splitting a string in PySpark
I tried "How to get a method decorated in Python"
I wrote a script to get a popular site in Japan
Get a Boolean in Flask's request
I get a can't set attribute when using @property in python
I want to print in a comprehension
I made a payroll program in Python!
How to get a stacktrace in python
I can't get the element in Selenium!
Get a token for conoha in python
I started Node.js in a virtual environment
I created a password tool in Python.
[Python] Get the files in a folder with Python
A memo that I wrote a quicksort in Python
Get the caller of a function in Python
I want to create a window in Python
I tried playing a typing game in Python
I wrote a class in Python3 and Java
[Memo] I tried a pivot table in Python
Get only the subclass elements in a list
Get a panoramic image in Google Street View
I get a UnicodeDecodeError when running with mod_wsgi
I wrote a design pattern in kotlin Prototype
I tried adding a Python3 module in C
Get a glimpse of machine learning in Python
[PyTorch] I was a little lost in torch.max ()
I made a tool to get new articles
I wrote a Japanese parser in Japanese using pyparsing.
I made a Caesar cryptographic program in Python.
Get a row containing a specific element in np.where
I was in vain because I couldn't get a send parent order with pybitflyer
I get a strange window when I use the open directory dialog in Tkinter
Draw a graph in Julia ... I tried a little analysis
I want to easily implement a timeout in python
I made a prime number generation program in Python
〇✕ I made a game
Get the file name in a folder using glob
I wrote a design pattern in kotlin Factory edition
I want to transition with a button in flask
I get an Import Error in Python Beautiful Soup
I wrote a design pattern in kotlin Builder edition
I want to use a python data source in Re: Dash to get query results
I want to write in Python! (2) Let's write a test
I wrote a design pattern in kotlin Singleton edition
I wrote a design pattern in kotlin Adapter edition
I made a script to put a snippet in README.md
I tried to implement a pseudo pachislot in Python
I wrote a design pattern in kotlin, Iterator edition
I want to randomly sample a file in Python
I get an error when I put opencv in pyautoGUI
dict in dict Makes a dict a dict
I want to work with a robot in python.
BigQuery-If you get a Reason: responseTooLarge error in Python
Get date in Python
I participated in competitive programming in a week after I started programming
I made a prime number generation program in Python 2
I got a sqlite3.OperationalError
I can't manipulate iframes in a page with Selenium