K-平均クラスタリング

The K-Means algorithm clusters data by trying to separate samples in n groups of equal variance, minimizing a criterion known as the inertia or within-cluster sum-of-squares. このアルゴリズムは指定されるクラスタの数を必要とします。

コンストラクタのパラメータ

  • $clustersNumber - 見つけるクラスタの数
  • $initialization - 初期化メソッド。デフォルトは kmeans++ (以下を見てください)
$kmeans = new KMeans(2);
$kmeans = new KMeans(4, KMeans::INIT_RANDOM);

クラスタリング

標本をクラスタに分割するには、単純にcluster メソッドを使ってください。中に標本を持つクラスタの配列を返します。

$samples = [[1, 1], [8, 7], [1, 2], [7, 8], [2, 1], [8, 9]];

$kmeans = new KMeans(2);
$kmeans->cluster($samples);
// return [0=>[[1, 1], ...], 1=>[[8, 7], ...]] 

初期化メソッド

kmeans++ (デフォルト)

K-means++ method selects initial cluster centers for k-mean clustering in a smart way to speed up convergence. It use the DASV seeding method consists of finding good initial centroids for the clusters.

random

ランダム初期化メソッドは完全にランダムな重心を選択します。It get the space boundaries to avoid placing clusters centroid too far from samples data.