在维基百科上,有关于如何根据随机方法初始化 kmeans 簇位置的描述。
在 pyclustering ,一个python集群库,各种集群都是用高性能c核实现的。这个核心比 numpy/sklearn 更快,所以我想避免在 sklearn/numpy 中实现任何东西(否则我现在可能会失去代码的快速感觉)。
但是,kmeans class需要初始集群位置列表才能开始。在 pyclustering 中初始化这些簇位置的预期方法是什么?
最佳答案
有automatically generated pyclustering documentation其中描述了kmeans算法的API。
例如,您有一个 2D 数据,其中应提取两个簇,然后您需要指定初始中心(pyclustering 不会生成初始中心,它们应由用户提供):
kmeans_instance = kmeans(sample, [ [0.0, 0.1], [2.5, 2.6] ], ccore = True);
其中 [0.0, 0.1] 是第一个簇的初始中心,[2.5, 2.6] 是第二个簇的初始中心。标志“ccore = True”用于 CCORE 库的使用。
运行处理:
kmeans_instance.process();
获取聚类结果:
clusters = kmeans_instance.get_clusters(); # list of clusters
centers = kmeans_instance.get_centers(); # list of cluster centers.
可视化获得的结果:
visualizer = cluster_visualizer();
visualizer.append_clusters(clusters, sample);
visualizer.append_cluster(start_centers, marker = '*', markersize = 20);
visualizer.append_cluster(centers, marker = '*', markersize = 20);
visualizer.show();
Click here to see example of result visualization
使用示例可以在:'pyclustering/cluster/example/kmeans_examples.py'中找到
$ ls pyclustering/cluster/examples/ -1
__init__.py
agglomerative_examples.py
birch_examples.py
clarans_examples.py
cure_examples.py
dbscan_examples.py
dbscan_segmentation.py
general_examples.py
hsyncnet_examples.py
kmeans_examples.py <--- kmeans examples
kmeans_segmentation.py
kmedians_examples.py
kmedoids_examples.py
optics_examples.py
rock_examples.py
somsc_examples.py
syncnet_examples.py
syncsom_examples.py
syncsom_segmentation.py
xmeans_examples.py
关于python - pyclustering : intended method of initializing kmeans,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45698986/