# Balanced K-Means clustering in PyTorch
Balanced K-Means clustering in Pytorch with strong GPU acceleration.
# Installation
As easy as:
`pip install balanced_kmeans`
# Getting started
First things first: Classical kmeans algorithm as easy as
```
from balanced_kmeans import kmeans
# experiment constants
N = 10000
batch_size = 10
num_clusters = 100
device = 'cuda'
cluster_size = N // num_clusters
X = torch.rand(batch_size, N, dim, device=device)
choices, centers = kmeans(X, num_clusters=num_clusters)
```
Now, if you want balanced kmeans you can run:
```
from balanced_kmeans import kmeans_equal
N = 10000
batch_size = 10
num_clusters = 100
device = 'cuda'
cluster_size = N // num_clusters
X = torch.rand(batch_size, N, dim, device=device)
choices, centers = kmeans_equal(X, num_clusters=num_clusters)
```
By default, forge initialization scheme is used for initial cluster centers.
However, you may change the initial cluster centers by providing the keyword
argument `initial_state` to either `kmeans` or `kmeans_equal`.
基于GPU加速+Pytorch的K-Means聚类实现-附项目源码-优质项目实战.zip
版权申诉
86 浏览量
2024-05-25
16:56:53
上传
评论
收藏 7KB ZIP 举报
__AtYou__
- 粉丝: 1895
- 资源: 648
最新资源
- GM-T 108-2021 诱骗态84量子密钥分配产品技术规范
- baiduwenku_AndroidPhone_1027470h-1718616594228.apk
- 飞飞CMS仿零零七影院网站模板
- GM-T 0109-2021 基于云计算的电子签名服务技术要求
- content_1718616449016.docx
- GM-T 0118-2022 浏览器数字证书应用接口规范
- 基于微信考试答题小程序设计与实现
- jdk-8u191-linux-x64.tar.gz jdk-8u191-linux-x64.tar.gz
- 输入文件备份位置自动备份测量程序操作方法
- GM-T 0122-2022 区块链密码检测规范
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈