powered by
This function performs clustering on a numeric matrix using one of six common clustering methods: KMeans, Hierarchical, DBSCAN, PAM, Gaussian Mixture Model (GMM), or Spectral Clustering.
run_clustering(data, method, k = 3, eps = 0.5, minPts = 5)
A list containing two elements:
A vector of cluster labels assigned to each observation.
An object of class silhouette representing silhouette widths.
silhouette
A numeric matrix or data frame, typically standardized, to be clustered.
A string indicating the clustering method to use. Options are: "KMeans", "Hierarchical", "DBSCAN", "PAM", "GMM", "Spectral".
An integer specifying the number of clusters. Required for KMeans, Hierarchical, PAM, GMM, and Spectral.
A numeric value specifying the epsilon parameter for DBSCAN. Default is 0.5.
An integer specifying the minimum number of points for DBSCAN. Default is 5.
data(iris) result <- run_clustering(scale(iris[, 1:4]), method = "KMeans", k = 3) print(result$cluster) if (interactive()) { plot(result$silhouette) }
Run the code above in your browser using DataLab