8  Clustering

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

select_clust()
.:select_clust
rtemis supports the following clustering algorithms:

      Name                                                 Description
    CMeans                                    Fuzzy C-means Clustering
    DBSCAN Density-based spatial clustering of applications with noise
       EMC                         Expectation Maximization Clustering
    HARDCL                                   Hard Competitive Learning
    HOPACH     Hierarchical Ordered Partitioning And Collapsing Hybrid
 H2OKMeans                                      H2O K-Means Clustering
    KMeans                                          K-Means Clustering
 MeanShift                                       Mean Shift Clustering
      NGAS                                       Neural Gas Clustering
       PAM                                 Partitioning Around Medoids
      PAMK               Partitioning Around Medoids with k estimation
      SPEC                                         Spectral Clustering

Let’s cluster iris and we shall also use an NMF decomposition as we saw above to project to 2 dimensions.

x <- iris[, 1:4]
iris_NMF <- d_NMF(x, k = 2)
01-07-24 00:23:40 Hello, egenn [d_NMF]
01-07-24 00:23:41 ||| Input has dimensions 150 rows by 4 columns, [d_NMF]
01-07-24 00:23:41     interpreted as 150 cases with 4 features. [d_NMF]
01-07-24 00:23:41 Running Non-negative Matrix Factorization... [d_NMF]
01-07-24 00:23:41 Completed in 0.01 minutes (Real: 0.78; User: 0.71; System: 0.03) [d_NMF]


8.0.1 K-Means

iris_KMEANS <- c_KMeans(x, k = 3)
01-07-24 00:23:41 Hello, egenn [c_KMeans]
01-07-24 00:23:41 Performing K-means Clustering with k = 3... [c_KMeans]
01-07-24 00:23:41 Completed in 1.9e-03 minutes (Real: 0.11; User: 0.09; System: 0.01) [c_KMeans]

mplot3_xy(iris_NMF$projections.train[, 1], iris_NMF$projections.train[, 2],
          group = iris_KMEANS$clusters.train, 
          main = "KMEANS on iris",
          xlab = "1st NMF component", 
          ylab = "2nd NMF component")

8.0.2 Partitioning Around Medoids with k estimation (PAMK)

iris_pamk <- c_PAMK(x, krange = 3:10)
01-07-24 00:23:41 Hello, egenn [c_PAMK]
01-07-24 00:23:42 Partitioning Around Medoids... [c_PAMK]
01-07-24 00:23:42 Estimated optimal number of clusters: 3 [c_PAMK]
01-07-24 00:23:42 Completed in 0.01 minutes (Real: 0.49; User: 0.41; System: 0.03) [c_PAMK]

mplot3_xy(iris_NMF$projections.train[, 1], iris_NMF$projections.train[, 2],
          group = iris_pamk$clusters.train, 
          main = "PAM on iris",
          xlab = "1st NMF component", 
          ylab = "2nd NMF component")

8.0.3 Neural Gas

iris_NGAS <- c_NGAS(x, k = 3)
01-07-24 00:23:42 Hello, egenn [c_NGAS]
01-07-24 00:23:42 Performing Neural Gas clustering with k = 3... [c_NGAS]
01-07-24 00:23:42 Completed in 2.3e-04 minutes (Real: 0.01; User: 0.01; System: 0.00) [c_NGAS]

mplot3_xy(iris_NMF$projections.train[, 1], iris_NMF$projections.train[, 2],
          group = iris_NGAS$clusters.train, 
          main = "NGAS on iris",
          xlab = "1st NMF component", 
          ylab = "2nd NMF component")

8.0.4 Hard Competitive Learning

iris_hardcl <- c_HARDCL(x, k = 3)
01-07-24 00:23:42 Hello, egenn [c_HARDCL]
01-07-24 00:23:42 Running Hard Competitive Learning with k = 3... [c_HARDCL]
01-07-24 00:23:42 Completed in 1.5e-04 minutes (Real: 0.01; User: 0.01; System: 0.00) [c_HARDCL]

mplot3_xy(iris_NMF$projections.train[, 1], iris_NMF$projections.train[, 2],
          group = iris_hardcl$clusters.train, 
          main = "HARDCL on iris",
          xlab = "1st NMF component", 
          ylab = "2nd NMF component")

8.0.5 Hierarchical Ordering and Partitioning Hybrid

iris_hopach <- c_HOPACH(x)
01-07-24 00:23:42 Running HOPACH clustering... [c_HOPACH]
01-07-24 00:23:43 HOPACH identified 3 clusters (sizes: 50, 44, 56) [c_HOPACH]
01-07-24 00:23:43 Completed in 0.01 minutes (Real: 0.34; User: 0.33; System: 0.01) [c_HOPACH]

mplot3_xy(iris_NMF$projections.train[, 1], iris_NMF$projections.train[, 2],
          group = iris_hopach$clusters.train, 
          main = "HOPACH on iris",
          xlab = "1st NMF component", 
          ylab = "2nd NMF component")