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-21 19:40:49  [decomp]
2026-02-21 19:40:49 Input: 150 cases x 4 features. [summarize_unsupervised]
2026-02-21 19:40:49 Decomposing with ICA... [decomp]
2026-02-21 19:40:49 Checking unsupervised data...  [check_unsupervised_data]
2026-02-21 19:40:49 Decomposing with ICA ... [decom_ICA]
Centering
colstandard
Whitening
Symmetric FastICA using logcosh approx. to neg-entropy function
Iteration 1 tol=0.679655
Iteration 2 tol=0.130440
Iteration 3 tol=0.000199
Iteration 4 tol=0.000013
2026-02-21 19:40:49  Done in 0.01 seconds. [decomp]

14.0.1 K-Means

iris_KMeans <- cluster(
  x,
  algorithm = "KMeans",
  config = setup_KMeans(k = 3L)
)
2026-02-21 19:40:49  [cluster]
2026-02-21 19:40:49 Input: 150 cases x 4 features. [summarize_unsupervised]
2026-02-21 19:40:49 Clustering with KMeans... [cluster]
2026-02-21 19:40:49 Checking unsupervised data...  [check_unsupervised_data]
2026-02-21 19:40:49 Clustering with KMeans ... [cluster_KMeans]
2026-02-21 19:40:49  Done in 0.12 seconds. [cluster]
iris_KMeans
<KMeans Clustering>
   clust: (S4 object of class: 'kcca')
       k: <int> 3
clusters: <int> 3, 3, 3, 3...
  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-21 19:40:49  [cluster]
2026-02-21 19:40:49 Input: 150 cases x 4 features. [summarize_unsupervised]
2026-02-21 19:40:49 Clustering with CMeans... [cluster]
2026-02-21 19:40:49 Checking unsupervised data...  [check_unsupervised_data]
2026-02-21 19:40:49 Clustering with CMeans ... [cluster_CMeans]
Iteration:   1, Error:  1.1826558407
Iteration:   2, Error:  0.6593148748
Iteration:   3, Error:  0.4707373129
Iteration:   4, Error:  0.4314881495
Iteration:   5, Error:  0.4162812868
Iteration:   6, Error:  0.4093049975
Iteration:   7, Error:  0.4060446197
Iteration:   8, Error:  0.4045492870
Iteration:   9, Error:  0.4038810616
Iteration:  10, Error:  0.4035890420
Iteration:  11, Error:  0.4034635076
Iteration:  12, Error:  0.4034101491
Iteration:  13, Error:  0.4033876391
Iteration:  14, Error:  0.4033781896
Iteration:  15, Error:  0.4033742355
Iteration:  16, Error:  0.4033725843
Iteration:  17, Error:  0.4033718957
Iteration:  18, Error:  0.4033716088
Iteration:  19, Error:  0.4033714894
Iteration:  20, Error:  0.4033714396
Iteration:  21, Error:  0.4033714189
Iteration:  22, Error:  0.4033714103
Iteration:  23 converged, Error:  0.4033714067
2026-02-21 19:40:49  Done in 0.03 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-21 19:40:49  [cluster]
2026-02-21 19:40:49 Input: 150 cases x 4 features. [summarize_unsupervised]
2026-02-21 19:40:49 Clustering with HardCL... [cluster]
2026-02-21 19:40:49 Checking unsupervised data...  [check_unsupervised_data]
2026-02-21 19:40:49 Clustering with HardCL ... [cluster_HardCL]
2026-02-21 19:40:49  Done in 0.02 seconds. [cluster]
iris_HardCL
<HardCL Clustering>
   clust: (S4 object of class: 'kcca')
       k: <int> 3
clusters: <int> 3, 3, 3, 3...
  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-21 19:40:49  [cluster]
2026-02-21 19:40:49 Input: 150 cases x 4 features. [summarize_unsupervised]
2026-02-21 19:40:49 Clustering with NeuralGas... [cluster]
2026-02-21 19:40:49 Checking unsupervised data...  [check_unsupervised_data]
2026-02-21 19:40:49 Clustering with NeuralGas ... [cluster_NeuralGas]
2026-02-21 19:40:49  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