Learn R Programming

tidydr (version 0.0.6)

nk: nk

Description

Choose best K (number of clusters)

Usage

nk(data, k)

Value

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

Arguments

data

input data (a matrix or data frame)

k

a vector of candidate number of clusters

Author

Guangchuang Yu

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)

Examples

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

Run the code above in your browser using DataLab