14  Cluster

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

available_clustering()
     CMeans: Fuzzy C-means Clustering
     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))
2025-06-08 08:20:21 Hello. [decomp]
2025-06-08 08:20:21 Input: 150 cases x 4 features.
2025-06-08 08:20:21 Decomposing with ICA... [decomp]
2025-06-08 08:20:21 Checking unsupervised data... [check_unsupervised_data]

Centering
colstandard
Whitening
Symmetric FastICA using logcosh approx. to neg-entropy function
Iteration 1 tol=0.021070
Iteration 2 tol=0.001818
Iteration 3 tol=0.001090
Iteration 4 tol=0.000584
Iteration 5 tol=0.000273
Iteration 6 tol=0.000114
Iteration 7 tol=0.000045
2025-06-08 08:20:21 Done in 0.01 seconds. [decomp]

14.0.1 K-Means

iris_KMeans <- cluster(
  x,
  algorithm = "KMeans",
  parameters = setup_KMeans(k = 3L)
)
2025-06-08 08:20:21 Hello. [cluster]
2025-06-08 08:20:21 Input: 150 cases x 4 features.
2025-06-08 08:20:21 Clustering with KMeans... [cluster]
2025-06-08 08:20:22 Checking unsupervised data... [check_unsupervised_data]
2025-06-08 08:20:22 Done in 0.18 seconds. [cluster]
iris_KMeans
.:KMeans Clustering

       clust: (S4 object of class: 'kcca')
           k: <int> 3
    clusters: <int> 3, 3, 3, 3...
  parameters:  
              KMeans ClusteringParameters
                 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",
  parameters = setup_CMeans(k = 3L)
)
2025-06-08 08:20:22 Hello. [cluster]
2025-06-08 08:20:22 Input: 150 cases x 4 features.
2025-06-08 08:20:22 Clustering with CMeans... [cluster]
2025-06-08 08:20:22 Checking unsupervised data... [check_unsupervised_data]

Iteration:   1, Error:  0.9529189884
Iteration:   2, Error:  0.4350755624
Iteration:   3, Error:  0.4057977923
Iteration:   4, Error:  0.4041266271
Iteration:   5, Error:  0.4036691859
Iteration:   6, Error:  0.4034953360
Iteration:   7, Error:  0.4034233983
Iteration:   8, Error:  0.4033931930
Iteration:   9, Error:  0.4033805153
Iteration:  10, Error:  0.4033752075
Iteration:  11, Error:  0.4033729899
Iteration:  12, Error:  0.4033720648
Iteration:  13, Error:  0.4033716793
Iteration:  14, Error:  0.4033715187
Iteration:  15, Error:  0.4033714518
Iteration:  16, Error:  0.4033714240
Iteration:  17, Error:  0.4033714124
Iteration:  18 converged, Error:  0.4033714076
2025-06-08 08:20:22 Done in 0.01 seconds. [cluster]
iris_CMeans
.:CMeans Clustering

       clust: object of class: fclust 
           k: <int> 3
    clusters: <int> 1, 1, 1, 1...
  parameters:  
              CMeans ClusteringParameters
                     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",
  parameters = setup_HardCL(k = 3L)
)
2025-06-08 08:20:22 Hello. [cluster]
2025-06-08 08:20:22 Input: 150 cases x 4 features.
2025-06-08 08:20:22 Clustering with HardCL... [cluster]
2025-06-08 08:20:22 Checking unsupervised data... [check_unsupervised_data]
2025-06-08 08:20:22 Done in 0.01 seconds. [cluster]
iris_HardCL
.:HardCL Clustering

       clust: (S4 object of class: 'kcca')
           k: <int> 3
    clusters: <int> 1, 1, 1, 1...
  parameters:  
              HardCL ClusteringParameters
                 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",
  parameters = setup_NeuralGas(k = 3L)
)
2025-06-08 08:20:22 Hello. [cluster]
2025-06-08 08:20:22 Input: 150 cases x 4 features.
2025-06-08 08:20:22 Clustering with NeuralGas... [cluster]
2025-06-08 08:20:22 Checking unsupervised data... [check_unsupervised_data]
2025-06-08 08:20:22 Done in 0.02 seconds. [cluster]
iris_NeuralGas
.:NeuralGas Clustering

       clust: (S4 object of class: 'kcca')
           k: <int> 3
    clusters: <int> 1, 1, 1, 1...
  parameters:  
              NeuralGas ClusteringParameters
                 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