PHPackages                             medansoftware/kmeans-algorithm-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. medansoftware/kmeans-algorithm-php

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

medansoftware/kmeans-algorithm-php
==================================

v1.0.0(5y ago)28MITPHPPHP &gt;=5.5

Since Jul 31Pushed 1y ago1 watchersCompare

[ Source](https://github.com/medansoftware/KMeans-Algorithm-PHP)[ Packagist](https://packagist.org/packages/medansoftware/kmeans-algorithm-php)[ RSS](/packages/medansoftware-kmeans-algorithm-php/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

PHP K-Means Library
===================

[](#php-k-means-library)

Installation via [composer](https://getcomposer.org)
----------------------------------------------------

[](#installation-via-composer)

```
composer require medansoftware/kmeans-algorithm-php
```

How to use
----------

[](#how-to-use)

### Example 1 [Video Refrence](https://www.youtube.com/watch?v=MayK_kwJgv4)

[](#example-1-video-refrence)

```
$Kmeans = new \Algorithm\Kmeans;
$Kmeans->setAttributes(array(
	'A', 'B'
));

$Kmeans->setDataFromArgs(1, 1);  // "First Argument" assign to "First Attribute" and "Second Argument" assign to "Second Attribute" etc.
$Kmeans->setDataFromArgs(2, 1);
$Kmeans->setDataFromArgs(4, 3);
$Kmeans->setDataFromArgs(5, 4);

$Kmeans->setClusterCount(2); // Set amount of cluster
$Kmeans->setCentroid(0, 1); // Choose centroid from array key or left blank will auto fill

// Looping for iteration
$i = 1;
for (; ; ) {
	$Kmeans->setIteration($i);
	$Kmeans->run();
	if ($Kmeans->isDone()) {

		echo "";
		print_r ($Kmeans->getCentroid());
		echo "";

		echo 'Iteration ended on : '.$Kmeans->countIterations();

		echo "";
		print_r ($Kmeans->getAllResults());
		echo "";
		break;
	}
	$i++;
}
```

### Example 2 [Video Refrence](https://www.youtube.com/watch?v=FUwxw9Rv4Ls)

[](#example-2-video-refrence)

```
$Kmeans = new \Algorithm\Kmeans;
$Kmeans->setAttributes(array(
	'x'
));

$Kmeans->setDataFromArgs(1);
$Kmeans->setDataFromArgs(2);
$Kmeans->setDataFromArgs(6);
$Kmeans->setDataFromArgs(7);
$Kmeans->setDataFromArgs(8);
$Kmeans->setDataFromArgs(10);
$Kmeans->setDataFromArgs(15);
$Kmeans->setDataFromArgs(17);
$Kmeans->setDataFromArgs(20);

$Kmeans->setClusterCount(3); // Set amount of cluster
$Kmeans->setCentroid(1, 5, 7); // Choose centroid from array key or left blank will auto fill

// Looping for iteration
$i = 1;
for (; ; ) {
	$Kmeans->setIteration($i);
	$Kmeans->run();
	if ($Kmeans->isDone()) {

		echo "";
		print_r ($Kmeans->getCentroid());
		echo "";

		echo 'Iteration ended on : '.$Kmeans->countIterations();

		echo "";
		print_r ($Kmeans->catchLogs());
		echo "";
		break;
	}
	$i++;
}
```

**Refrence :**

- [Code](https://codepad.co/snippet/php-kmeans-library)
- [Article](http://studyshut.blogspot.com/2018/12/contoh-perhitungan-manual-menggunakan.html)
- [Video (Indonesian)](https://www.youtube.com/watch?v=MayK_kwJgv4)

**Made with ❤️ + ☕ ~ Agung Dirgantara**

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance35

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2117d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/24e8e95a612ecb77482b7ba9f36439d1edcb2509205a84cc0f71b53fad2eeaca?d=identicon)[agoenks29D](/maintainers/agoenks29D)

---

Top Contributors

[![agoenks29D](https://avatars.githubusercontent.com/u/11814324?v=4)](https://github.com/agoenks29D "agoenks29D (4 commits)")

### Embed Badge

![Health badge](/badges/medansoftware-kmeans-algorithm-php/health.svg)

```
[![Health](https://phpackages.com/badges/medansoftware-kmeans-algorithm-php/health.svg)](https://phpackages.com/packages/medansoftware-kmeans-algorithm-php)
```

###  Alternatives

[hanson/laravel-work-exception

133.8k](/packages/hanson-laravel-work-exception)[wujunze/money-wrapper

MoneyPHP Wrapper

113.8k](/packages/wujunze-money-wrapper)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
