annoviko / pyclustering

pyclustering is a Python, C++ data mining library.
https://pyclustering.github.io/
BSD 3-Clause "New" or "Revised" License
1.16k stars 249 forks source link

Predict function throwing error on demo code. #671

Open EricCacciavillani opened 3 years ago

EricCacciavillani commented 3 years ago

Hi sorry but I think I found a massive bug in the code. For some reason when I call predict on the model it gives me back the following: image

I think this might be a massive bug problem...can anyone help with this?

EricCacciavillani commented 3 years ago

It seems like a very simple fix of changing object1 and object2 to the correct datatype.

ShigemichiMatsuzaki commented 2 years ago

Hi,

This may be caused because the cluster centers calculated in process are stored as list when the k-means is performed via CCORE (the C/C++ library for pyclustering). I've encountered the same issue and fixed this by simply editing the function process() in the code kmeans.py like below:

     def process(self):
         """!
         @brief Performs cluster analysis in line with rules of K-Means algorithm.

         @return (kmeans) Returns itself (K-Means instance).

         @see get_clusters()
         @see get_centers()

         """

         if len(self.__pointer_data[0]) != len(self.__centers[0]):
             raise ValueError("Dimension of the input data and dimension of the initial cluster centers must be equal.")

         if self.__ccore is True:
             self.__process_by_ccore()
         else:
             self.__process_by_python()

         # Editted
         self.__centers = numpy.array(self.__centers)

         return self

Although this fixed my problem, I didn't look through the entire code and am not sure this is a recommended way. (I (we) might have missed some necessary processes.) I'll appreciate it if someone gives me some comments.