silhouette: Measures silhouette between clusters

View source: R/metric-silhouette.R

silhouetteR Documentation

Measures silhouette between clusters

Description

Measures silhouette between clusters

Usage

silhouette(object, new_data = NULL, dists = NULL, dist_fun = Rfast::Dist)

Arguments

object

A fitted tidyclust model

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

silhouette_avg() is the corresponding cluster metric function that returns the average of the values given by silhouette().

Value

A tibble giving the silhouette for each observation.

Examples

kmeans_spec <- k_means(num_clusters = 5) %>%
  set_engine("stats")

kmeans_fit <- fit(kmeans_spec, ~., mtcars)

dists <- mtcars %>%
  as.matrix() %>%
  dist()

silhouette(kmeans_fit, dists = dists)

tidyclust documentation built on July 3, 2024, 1:06 a.m.