# Set number of clusters to be equal to number of known ransomware groups (ignoring the whites) n_groups <- length(unique(ransomware$label)) - 1 n_groups # K-Means Clustering # https://www.polarmicrobes.org/microbial-community-segmentation-with-r/ som.cluster <- kmeans(data.frame(som_model2$codes[[1]]), centers=n_groups) plot(som_model2, main = '', type = "property", property = som.cluster$cluster, palette.name = topo.colors) add.cluster.boundaries(som_model2, som.cluster$cluster) # Hierarchical Clustering # https://www.datacamp.com/community/tutorials/hierarchical-clustering-R som.cluster <- hclust(dist(data.frame(som_model2$codes[[1]])), method="mcquitty") plot(som_model2, main = '', type = "property", property = som.cluster$order, palette.name = topo.colors) add.cluster.boundaries(som_model2, som.cluster$order) # Clean up environment #rm(som.cluster)