pyclustering icon indicating copy to clipboard operation
pyclustering copied to clipboard

Predict function throwing error on demo code.

Open EricCacciavillani opened this issue 3 years ago • 2 comments

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 avatar May 01 '21 14:05 EricCacciavillani

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

EricCacciavillani avatar May 01 '21 15:05 EricCacciavillani

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.

ShigemichiMatsuzaki avatar Jan 29 '22 14:01 ShigemichiMatsuzaki