Learn R Programming

tidyclust (version 0.2.4)

silhouette_avg: Measures average silhouette across all observations

Description

Measures average silhouette across all observations

Usage

silhouette_avg(object, ...)

# S3 method for cluster_spec silhouette_avg(object, ...)

# S3 method for cluster_fit silhouette_avg(object, new_data = NULL, dists = NULL, dist_fun = NULL, ...)

# S3 method for workflow silhouette_avg(object, new_data = NULL, dists = NULL, dist_fun = NULL, ...)

silhouette_avg_vec( object, new_data = NULL, dists = NULL, dist_fun = philentropy::distance, ... )

Value

A double; the average silhouette.

Arguments

object

A fitted kmeans tidyclust model

...

Other arguments passed to methods.

new_data

A dataset to predict on. If NULL, uses trained clustering.

dists

A distance matrix. Used if new_data is NULL.

dist_fun

A function for calculating distances between observations. Defaults to Euclidean distance on processed data.

Details

Not to be confused with silhouette() that returns a tibble with silhouette for each observation.

See Also

Other cluster metric: sse_ratio(), sse_total(), sse_within_total()

Examples

Run this code
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)

Run the code above in your browser using DataLab