public class KMeans extends PartitionClustering<double[]> implements ICentroidClustering
However, the k-means algorithm has at least two major theoretic shortcomings:
We also use k-d trees to speed up each k-means step as described in the filter algorithm by Kanungo, et al.
K-means is a hard clustering method, i.e. each sample is assigned to a specific cluster. In contrast, soft clustering, e.g. the Expectation-Maximization algorithm for Gaussian mixtures, assign samples to different clusters with different probabilities.
BBDTree| Constructor and Description |
|---|
KMeans()
Initializes a new instance of the KMeans class.
|
KMeans(int k)
Initializes a new instance of the KMeans class.
|
KMeans(int k,
int maxIteration)
Initializes a new instance of the KMeans class.
|
KMeans(int k,
int maxIteration,
int maxRuns)
Initializes a new instance of the KMeans class.
|
| Modifier and Type | Method and Description |
|---|---|
void |
Compute(DatasetClassification dataset)
Compute the data.
|
void |
Compute(double[][] input)
Compute the data.
|
double |
distortion()
Returns the distortion.
|
double[][] |
getCentroids()
Returns the centroids.
|
int |
getClusters() |
static KMeans |
lloyd(double[][] input,
int k)
The implementation of Lloyd algorithm as a benchmark.
|
static KMeans |
lloyd(double[][] input,
int k,
int maxIteration)
The implementation of Lloyd algorithm as a benchmark.
|
static KMeans |
lloyd(double[][] input,
int k,
int maxIteration,
int runs)
The implementation of Lloyd algorithm as a benchmark.
|
int |
Predict(double[] x)
Cluster a new instance.
|
void |
setCluster(int k) |
java.lang.String |
toString() |
getClusterLabel, getClusterSize, getNumClusterspublic KMeans()
public KMeans(int k)
k - Number of the clusters.public KMeans(int k,
int maxIteration)
k - Number of the clusters.maxIteration - Maximum iteration.public KMeans(int k,
int maxIteration,
int maxRuns)
k - Number of the clusters.maxIteration - Maximum iteration.maxRuns - Perform KMeans n times.public double distortion()
public double[][] getCentroids()
getCentroids in interface ICentroidClusteringpublic int getClusters()
public void setCluster(int k)
public void Compute(DatasetClassification dataset)
ICentroidClusteringCompute in interface ICentroidClusteringdataset - Dataset.public void Compute(double[][] input)
ICentroidClusteringCompute in interface ICentroidClusteringinput - Data.public int Predict(double[] x)
Predict in interface ICentroidClusteringx - a new instance.public static KMeans lloyd(double[][] input, int k)
input - the input data of which each row is a sample.k - the number of clusters.public static KMeans lloyd(double[][] input, int k, int maxIteration)
data - the input data of which each row is a sample.k - the number of clusters.maxIteration - the maximum number of iterations for each running.public static KMeans lloyd(double[][] input, int k, int maxIteration, int runs)
data - the input data of which each row is a sample.k - the number of clusters.maxIteration - the maximum number of iterations for each running.runs - the number of runs of K-Means algorithm.public java.lang.String toString()
toString in class java.lang.Object