View source: R/metric-silhouette.R
silhouette_avg | R Documentation |
Measures average silhouette across all observations
silhouette_avg(object, ...)
## S3 method for class 'cluster_spec'
silhouette_avg(object, ...)
## S3 method for class 'cluster_fit'
silhouette_avg(object, new_data = NULL, dists = NULL, dist_fun = NULL, ...)
## S3 method for class 'workflow'
silhouette_avg(object, new_data = NULL, dists = NULL, dist_fun = NULL, ...)
silhouette_avg_vec(
object,
new_data = NULL,
dists = NULL,
dist_fun = Rfast::Dist,
...
)
object |
A fitted kmeans tidyclust model |
... |
Other arguments passed to methods. |
new_data |
A dataset to predict on. If |
dists |
A distance matrix. Used if |
dist_fun |
A function for calculating distances between observations. Defaults to Euclidean distance on processed data. |
Not to be confused with silhouette()
that returns a tibble
with silhouette for each observation.
A double; the average silhouette.
Other cluster metric:
sse_ratio()
,
sse_total()
,
sse_within_total()
kmeans_spec <- k_means(num_clusters = 5) %>%
set_engine("stats")
kmeans_fit <- fit(kmeans_spec, ~., mtcars)
dists <- mtcars %>%
as.matrix() %>%
dist()
silhouette_avg(kmeans_fit, dists = dists)
silhouette_avg_vec(kmeans_fit, dists = dists)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.