Skip to content

Instantly share code, notes, and snippets.

@mikemahoney218
Last active June 15, 2022 22:10
Show Gist options
  • Save mikemahoney218/6c32b554d84e3c13cd68c628928425ca to your computer and use it in GitHub Desktop.
Save mikemahoney218/6c32b554d84e3c13cd68c628928425ca to your computer and use it in GitHub Desktop.
Testing several clustering methods in spatial_clustering_cv
# remotes::install_github('tidymodels/spatialsample')
library(spatialsample)
library(cluster)
make_clusters <- function(func) {
set.seed(123)
boston_canopy |>
spatial_clustering_cv(cluster_function = func) |>
autoplot()
}
function_list <- list(
"kmeans",
"hclust",
\(dists, v, ...) fanny(dists, v, maxit = 1e4)$clustering,
\(dists, v, ...) pam(dists, v)$clustering,
\(dists, v, ...) cutree(agnes(dists), v),
\(dists, v, ...) cutree(diana(dists), v)
)
lapply(function_list, make_clusters)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment