Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

predict error for kmeans #689

Open
BeHappyForMe opened this issue Jul 19, 2022 · 0 comments
Open

predict error for kmeans #689

BeHappyForMe opened this issue Jul 19, 2022 · 0 comments

Comments

@BeHappyForMe
Copy link

`from pyclustering.cluster.kmeans import kmeans, kmeans_visualizer
from pyclustering.cluster.center_initializer import kmeans_plusplus_initializer
from pyclustering.samples.definitions import FCPS_SAMPLES
from pyclustering.utils import read_sample
samples = read_sample(FCPS_SAMPLES.SAMPLE_TWO_DIAMONDS)
initial_centers = kmeans_plusplus_initializer(samples, 2).initialize()
kmeans_instance = kmeans(samples, initial_centers)
kmeans_instance.process()
clusters = kmeans_instance.get_clusters()
final_centers = kmeans_instance.get_centers()

kmeans_instance.predict(samples)`

and i meet this:


AttributeError Traceback (most recent call last)
/tmp/ipykernel_20827/3994711565.py in
----> 1 kmeans_instance.predict(samples)

~/envs/envs/spark_seg/lib/python3.7/site-packages/pyclustering/cluster/kmeans.py in predict(self, points)
441 for index_point in range(len(nppoints)):
442 if self.__metric.get_type() != type_metric.USER_DEFINED:
--> 443 differences[index_point] = self.__metric(nppoints[index_point], self.__centers)
444 else:
445 differences[index_point] = [self.__metric(nppoints[index_point], center) for center in self.__centers]

~/envs/envs/spark_seg/lib/python3.7/site-packages/pyclustering/utils/metric.py in call(self, point1, point2)
130
131 """
--> 132 return self.__calculator(point1, point2)
133
134

~/envs/envs/spark_seg/lib/python3.7/site-packages/pyclustering/utils/metric.py in euclidean_distance_square_numpy(object1, object2)
368
369 """
--> 370 if len(object1.shape) > 1 or len(object2.shape) > 1:
371 return numpy.sum(numpy.square(object1 - object2), axis=1).T
372 else:

AttributeError: 'list' object has no attribute 'shape'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant