13  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-01 13:22:13 👽Hello. [decomp]

  Input: 150 cases x 4 features.
2025-06-01 13:22:13 Decomposing with ICA... [decomp]
2025-06-01 13:22:13 Checking unsupervised data... [check_unsupervised_data]

Centering
Whitening
Symmetric FastICA using logcosh approx. to neg-entropy function
Iteration 1 tol=0.621644
Iteration 2 tol=0.100538
Iteration 3 tol=0.027552
Iteration 4 tol=0.027034
Iteration 5 tol=0.023269
Iteration 6 tol=0.021609
Iteration 7 tol=0.019336
Iteration 8 tol=0.017831
Iteration 9 tol=0.016004
Iteration 10 tol=0.014725
Iteration 11 tol=0.013222
Iteration 12 tol=0.012145
Iteration 13 tol=0.010909
Iteration 14 tol=0.010006
Iteration 15 tol=0.008992
Iteration 16 tol=0.008237
Iteration 17 tol=0.007406
Iteration 18 tol=0.006777
Iteration 19 tol=0.006096
Iteration 20 tol=0.005572
Iteration 21 tol=0.005015
Iteration 22 tol=0.004580
Iteration 23 tol=0.004124
Iteration 24 tol=0.003763
Iteration 25 tol=0.003390
Iteration 26 tol=0.003092
Iteration 27 tol=0.002786
Iteration 28 tol=0.002539
Iteration 29 tol=0.002290
Iteration 30 tol=0.002085
Iteration 31 tol=0.001881
Iteration 32 tol=0.001712
Iteration 33 tol=0.001545
Iteration 34 tol=0.001406
Iteration 35 tol=0.001269
Iteration 36 tol=0.001154
Iteration 37 tol=0.001042
Iteration 38 tol=0.000947
Iteration 39 tol=0.000856
Iteration 40 tol=0.000778
Iteration 41 tol=0.000703
Iteration 42 tol=0.000638
Iteration 43 tol=0.000577
Iteration 44 tol=0.000524
Iteration 45 tol=0.000474
Iteration 46 tol=0.000430
Iteration 47 tol=0.000389
Iteration 48 tol=0.000353
Iteration 49 tol=0.000319
Iteration 50 tol=0.000290
Iteration 51 tol=0.000262
Iteration 52 tol=0.000238
Iteration 53 tol=0.000215
Iteration 54 tol=0.000195
Iteration 55 tol=0.000177
Iteration 56 tol=0.000160
Iteration 57 tol=0.000145
Iteration 58 tol=0.000132
Iteration 59 tol=0.000119
Iteration 60 tol=0.000108
Iteration 61 tol=0.000098
2025-06-01 13:22:13 Completed in 2.8e-04 minutes (Real: 0.02; User: 0.01; System: 3e-03). [decomp]

13.0.1 K-Means

iris_KMeans <- cluster(
  x,
  algorithm = "KMeans",
  parameters = setup_KMeans(k = 3L)
)
2025-06-01 13:22:13 👽Hello. [cluster]

  Input: 150 cases x 4 features.
2025-06-01 13:22:13 Clustering with KMeans... [cluster]
2025-06-01 13:22:13 Checking unsupervised data... [check_unsupervised_data]
2025-06-01 13:22:14 Completed in 3.3e-03 minutes (Real: 0.20; User: 0.17; System: 0.01). [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"
)

13.0.2 Fuzzy C-Means

iris_CMeans <- cluster(
  x,
  algorithm = "CMeans",
  parameters = setup_CMeans(k = 3L)
)
2025-06-01 13:22:14 👽Hello. [cluster]

  Input: 150 cases x 4 features.
2025-06-01 13:22:14 Clustering with CMeans... [cluster]
2025-06-01 13:22:14 Checking unsupervised data... [check_unsupervised_data]

Iteration:   1, Error:  1.1027892503
Iteration:   2, Error:  0.4959685144
Iteration:   3, Error:  0.4080695197
Iteration:   4, Error:  0.4048884272
Iteration:   5, Error:  0.4039867977
Iteration:   6, Error:  0.4036306259
Iteration:   7, Error:  0.4034808602
Iteration:   8, Error:  0.4034174530
Iteration:   9, Error:  0.4033907078
Iteration:  10, Error:  0.4033794751
Iteration:  11, Error:  0.4033747727
Iteration:  12, Error:  0.4033728085
Iteration:  13, Error:  0.4033719892
Iteration:  14, Error:  0.4033716478
Iteration:  15, Error:  0.4033715056
Iteration:  16, Error:  0.4033714464
Iteration:  17, Error:  0.4033714218
Iteration:  18, Error:  0.4033714115
Iteration:  19 converged, Error:  0.4033714072
2025-06-01 13:22:14 Completed in 2.7e-04 minutes (Real: 0.02; User: 0.01; System: 3e-03). [cluster]
iris_CMeans
.:CMeans Clustering

       clust: object of class: fclust 
           k: <int> 3
    clusters: <int> 2, 2, 2, 2...
  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"
)

13.0.3 Hard Competitive Learning

iris_HardCL <- cluster(
  x,
  algorithm = "HardCL",
  parameters = setup_HardCL(k = 3L)
)
2025-06-01 13:22:14 👽Hello. [cluster]

  Input: 150 cases x 4 features.
2025-06-01 13:22:14 Clustering with HardCL... [cluster]
2025-06-01 13:22:14 Checking unsupervised data... [check_unsupervised_data]
2025-06-01 13:22:14 Completed in 1.7e-04 minutes (Real: 0.01; User: 0.01; System: 0.00). [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"
)

13.0.4 Neural Gas

iris_NeuralGas <- cluster(
  x,
  algorithm = "NeuralGas",
  parameters = setup_NeuralGas(k = 3L)
)
2025-06-01 13:22:14 👽Hello. [cluster]

  Input: 150 cases x 4 features.
2025-06-01 13:22:14 Clustering with NeuralGas... [cluster]
2025-06-01 13:22:14 Checking unsupervised data... [check_unsupervised_data]
2025-06-01 13:22:14 Completed in 2.2e-04 minutes (Real: 0.01; User: 0.01; System: 0.00). [cluster]
iris_NeuralGas
.:NeuralGas Clustering

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