nk: nk

View source: R/silinfo.R

nkR Documentation

nk

Description

Choose best K (number of clusters)

Usage

nk(data, k)

Arguments

data

input data (a matrix or data frame)

k

a vector of candidate number of clusters

Details

This function calculate the silhouette scores of each K (number of clusters). The output object can be used to choose the best K (via summary() or autoplot() methods)

Value

a silinfo object, which contains 'data' (original data), 'silinfo' (silhouette scores), and k (the input k vector)

Author(s)

Guangchuang Yu

Examples

x <- nk(iris[,-5], 2:8)
summary(x)
# to visualize the average silhouete score (y axis) with k (x axis)
autoplot(x)
# to visualize a PCA plot color by the choosing k
autoplot(x, k=3)

tidydr documentation built on Aug. 8, 2025, 7:07 p.m.