项目作者: NestorRV

项目描述 :
Constraind kmeans algorithm for Python 3.x.
高级语言: Python
项目地址: git://github.com/NestorRV/constrained_kmeans.git
创建时间: 2017-09-08T07:55:22Z
项目社区:https://github.com/NestorRV/constrained_kmeans

开源协议:GNU General Public License v3.0

下载


constrained_kmeans

This project is a version of the original work by Stanislaw Adaszewski. Here you can find the [original]. Stanislaw Adaszewski’s implementation is only compatible with Python 2.x, this one works with Python 3.x.

The algorithm consists of regular K-Means implementation where cluster assignment is done by solving Minimum Cost Flow (MCF) problem.

How to use it:

  1. from constrained_kmeans import constrained_kmeans
  2. (centroids, assignment, f) = constrained_kmeans(data, demand, maxiter=None, fixedprec=1e9)

where data is a vector of N-dimensional points (e.g. [[0, 0, 0], [1, 1, 1], [2,2,2]]), demand is a vector of minimum number of points for each cluster (implicitly it defines also the number of clusters), maxiter specifies the number of iterations after which to stop even if the algorithm didn’t converge, fixedprec allows to modify the distance multiplier. The return values are: C – cluster centers, M – assignments of point to clusters, f – last minimum cost flow solution. To further information see the [original] article.

[original]: http://adared.ch/constrained-k-means-implementation-in-python