14  Cluster

Use available_clustering() to get a listing of available clustering algorithms:

available_clustering()
     CMeans: Fuzzy C-means Clustering
     DBSCAN: Density-based spatial clustering of applications with noise
     HardCL: Hard Competitive Learning
     KMeans: K-Means Clustering
  NeuralGas: Neural Gas Clustering

First, let’s project the dataset to 3 dimensions for easier plotting of our clustering results.

x <- iris[, 1:4]
iris_ICA <- decomp(x, "ICA", setup_ICA(k = 3L))
2026-02-11 19:24:48  [decomp]
2026-02-11 19:24:48 Input: 150 cases x 4 features. [summarize_unsupervised]
2026-02-11 19:24:48 Decomposing with ICA... [decomp]
2026-02-11 19:24:48 Checking unsupervised data...  [check_unsupervised_data]
2026-02-11 19:24:48 Decomposing with ICA ... [decom_ICA]
Centering
colstandard
Whitening
Symmetric FastICA using logcosh approx. to neg-entropy function
Iteration 1 tol=0.072843
Iteration 2 tol=0.014999
Iteration 3 tol=0.148847
Iteration 4 tol=0.008588
Iteration 5 tol=0.009346
Iteration 6 tol=0.004481
Iteration 7 tol=0.001134
Iteration 8 tol=0.000298
Iteration 9 tol=0.000088
2026-02-11 19:24:48 ✔ Done in 0.01 seconds. [decomp]

14.0.1 K-Means

iris_KMeans <- cluster(
  x,
  algorithm = "KMeans",
  config = setup_KMeans(k = 3L)
)
2026-02-11 19:24:48  [cluster]
2026-02-11 19:24:48 Input: 150 cases x 4 features. [summarize_unsupervised]
2026-02-11 19:24:48 Clustering with KMeans... [cluster]
2026-02-11 19:24:48 Checking unsupervised data...  [check_unsupervised_data]
2026-02-11 19:24:48 Clustering with KMeans ... [cluster_KMeans]
2026-02-11 19:24:48 ✔ Done in 0.09 seconds. [cluster]
iris_KMeans
<KMeans Clustering>
   clust: (S4 object of class: 'kcca')
       k: <int> 3
clusters: <int> 2, 1, 1, 1...
  config:
          <KMeans ClusteringConfig>
             k: <int> 3
          dist: <chr> euclidean
draw_3Dscatter(
  iris_ICA$transformed,
  group = iris_KMeans$clusters,
  main = "KMeans on iris",
  xlab = "1st ICA component",
  ylab = "2nd ICA component",
  zlab = "3rd ICA component"
)

14.0.2 Fuzzy C-Means

iris_CMeans <- cluster(
  x,
  algorithm = "CMeans",
  config = setup_CMeans(k = 3L)
)
2026-02-11 19:24:48  [cluster]
2026-02-11 19:24:48 Input: 150 cases x 4 features. [summarize_unsupervised]
2026-02-11 19:24:48 Clustering with CMeans... [cluster]
2026-02-11 19:24:48 Checking unsupervised data...  [check_unsupervised_data]
2026-02-11 19:24:48 Clustering with CMeans ... [cluster_CMeans]
Iteration:   1, Error:  0.4080888593
Iteration:   2, Error:  0.4040875272
Iteration:   3, Error:  0.4036125930
Iteration:   4, Error:  0.4034690292
Iteration:   5, Error:  0.4034121176
Iteration:   6, Error:  0.4033884342
Iteration:   7, Error:  0.4033785196
Iteration:   8, Error:  0.4033743731
Iteration:   9, Error:  0.4033726417
Iteration:  10, Error:  0.4033719197
Iteration:  11, Error:  0.4033716188
Iteration:  12, Error:  0.4033714935
Iteration:  13, Error:  0.4033714414
Iteration:  14, Error:  0.4033714197
Iteration:  15, Error:  0.4033714106
Iteration:  16 converged, Error:  0.4033714069
2026-02-11 19:24:48 ✔ Done in 0.04 seconds. [cluster]
iris_CMeans
<CMeans Clustering>
   clust: object of class: fclust
       k: <int> 3
clusters: <int> 1, 1, 1, 1...
  config:
          <CMeans ClusteringConfig>
                 k: <int> 3
          max_iter: <int> 100
              dist: <chr> euclidean
            method: <chr> cmeans
                 m: <nmr> 2.00
          rate_par: <NUL> NULL
           weights: <nmr> 1.00
           control: (empty list)
draw_3Dscatter(
  iris_ICA$transformed,
  group = iris_CMeans$clusters,
  main = "CMeans on iris",
  xlab = "1st ICA component",
  ylab = "2nd ICA component",
  zlab = "3rd ICA component"
)

14.0.3 Hard Competitive Learning

iris_HardCL <- cluster(
  x,
  algorithm = "HardCL",
  config = setup_HardCL(k = 3L)
)
2026-02-11 19:24:48  [cluster]
2026-02-11 19:24:48 Input: 150 cases x 4 features. [summarize_unsupervised]
2026-02-11 19:24:48 Clustering with HardCL... [cluster]
2026-02-11 19:24:48 Checking unsupervised data...  [check_unsupervised_data]
2026-02-11 19:24:48 Clustering with HardCL ... [cluster_HardCL]
2026-02-11 19:24:48 ✔ Done in 0.02 seconds. [cluster]
iris_HardCL
<HardCL Clustering>
   clust: (S4 object of class: 'kcca')
       k: <int> 3
clusters: <int> 3, 2, 2, 2...
  config:
          <HardCL ClusteringConfig>
             k: <int> 3
          dist: <chr> euclidean
draw_3Dscatter(
  iris_ICA$transformed,
  group = iris_HardCL$clusters,
  main = "HardCL on iris",
  xlab = "1st ICA component",
  ylab = "2nd ICA component",
  zlab = "3rd ICA component"
)

14.0.4 Neural Gas

iris_NeuralGas <- cluster(
  x,
  algorithm = "NeuralGas",
  config = setup_NeuralGas(k = 3L)
)
2026-02-11 19:24:48  [cluster]
2026-02-11 19:24:48 Input: 150 cases x 4 features. [summarize_unsupervised]
2026-02-11 19:24:48 Clustering with NeuralGas... [cluster]
2026-02-11 19:24:48 Checking unsupervised data...  [check_unsupervised_data]
2026-02-11 19:24:48 Clustering with NeuralGas ... [cluster_NeuralGas]
2026-02-11 19:24:48 ✔ Done in 0.01 seconds. [cluster]
iris_NeuralGas
<NeuralGas Clustering>
   clust: (S4 object of class: 'kcca')
       k: <int> 3
clusters: <int> 2, 2, 2, 2...
  config:
          <NeuralGas ClusteringConfig>
             k: <int> 3
          dist: <chr> euclidean
draw_3Dscatter(
  iris_ICA$transformed,
  group = iris_NeuralGas$clusters,
  main = "NeuralGas on iris",
  xlab = "1st ICA component",
  ylab = "2nd ICA component",
  zlab = "3rd ICA component"
)
© 2025 E.D. Gennatas