2017 © Pedro Peláez
 

library kmeans

k-means clustering implemented in PHP

image

jacobemerick/kmeans

k-means clustering implemented in PHP

  • Thursday, July 31, 2014
  • by jacobemerick
  • Repository
  • 0 Watchers
  • 8 Stars
  • 1,082 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 1 Open issues
  • 2 Versions
  • 24 % Grown

The README.md

kmeans via PHP

This handly little class will calculate the k-means for a set of observations using PHP. k-means is a cool way to cluster data into groups based on relation - like clustering geographical data (using lat/lng) into a digestible summary. It is useful for detecting patterns in large data sets., (*1)

Usage

Let's say that you wanted to cluster a data set. The data must be in a multi-dimensional array, each value a numeric, though the size of each row has no constraint (n-dimensions ftw)., (*2)

$array = [
    [1, 1, 3],
    [3, 7, 6],
    [5, 8, 3],
    [1, 2, 1],
    [9, 10, 8],
    [4, 4, 4],
];

By observation you may suspect that this data can be clustered into 3 separate sets. To test, run the class., (*3)

$kmeans = new Jacobemerick\KMeans\Kmeans($array);
$kmeans->cluster(3); // cluster into three sets

$clustered_data = $kmeans->getClusteredData();
// $clustered_data = [
//     [[1, 1, 3], [1, 2, 1]],
//     [[3, 5, 6], [5, 4, 3], [4, 4, 4]],
//     [[9, 10, 8]],
// ];

$centroids = $kmeans->getCentroids();
// $centroids = [
//     [1, 1.5, 2],
//     [4, 4.33, 4.33],
//     [9, 10, 8],
// ];

Note: larger data sets will be more consistent - if you run this example multiple times your results may vary., (*4)

Installation

Through composer:, (*5)

$ composer require jacobemerick/kmeans:~1.0

The Versions

31/07 2014

dev-master

9999999-dev

k-means clustering implemented in PHP

  Sources   Download

MIT

The Requires

  • php >=5.3

 

statistics k-means data analysis clustering

31/07 2014

1.0.0

1.0.0.0

k-means clustering implemented in PHP

  Sources   Download

MIT

The Requires

  • php >=5.3

 

statistics k-means data analysis clustering