python - pyclustering : intended method of initializing kmeans

标签 python

在维基百科上,有关于如何根据随机方法初始化 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/

相关文章:

python 无法理解通过 Winsock 发送的 C++ 字符串

python - 在 Python 中将类或方法命名为 "class"的约定是什么?

Python,将二维列表中的所有数字除以 10 并返回二维列表

python - 使用 DataLoader 加载数据时跳过错误数据点

python - 我如何让这个容器自行删除?

python - 在 pytest 中,如何访问传递给测试的参数?

python - 转换为列表时保留 datetime64 的原始格式

python - 避免调整 Tkinter OptionMenu 按钮的大小

python - Django + Django REST Framework + PostgreSQL查询和序列化非常慢-并非“N + 1”情况

python - 获取 os.walk 命中 abspath