Skip to contents

Wraps stats::kmeans with Hartigan-Wong (the default).

Usage

morie_kmeans_clustering(
  x,
  n_clusters = 3L,
  n_init = 10L,
  max_iter = 300L,
  seed = 0L
)

Arguments

x

Numeric matrix.

n_clusters

Number of clusters K.

n_init

Number of random restarts.

max_iter

Max Lloyd iterations.

seed

RNG seed.

Value

Named list: estimate (inertia), labels, centers, inertia, n_iter, n_clusters, n, method.

Examples

morie_kmeans_clustering(x = rnorm(50))
#> $estimate
#> [1] 10.5644
#> 
#> $labels
#>  [1] 0 0 0 0 2 2 2 2 2 2 1 2 1 2 0 2 1 2 1 2 2 0 1 1 0 2 2 2 2 1 0 2 2 1 1 2 1 2
#> [39] 0 0 1 2 2 0 2 1 2 0 0 0
#> 
#> $centers
#>          [,1]
#> 1  1.37267814
#> 2 -1.13521991
#> 3  0.09104553
#> 
#> $inertia
#> [1] 10.5644
#> 
#> $n_iter
#> [1] 2
#> 
#> $n_clusters
#> [1] 3
#> 
#> $n
#> [1] 50
#> 
#> $method
#> [1] "K-means (Hartigan-Wong)"
#>