elbow: Use this function to find the best number of clusters

View source: R/clust.R

elbowR Documentation

Use this function to find the best number of clusters

Description

Use this function to find the best number of clusters

Usage

elbow(M, max.num.clusters = 25, metric = "euclidean", doPlot = T,
  num.clusters = NULL, bnc_method = "jump_threshold", ...)

Arguments

M

A matrix containing vectors for clustering. Each row defines a vector.

max.num.clusters

maximum number of clusters

metric

Either 'euclidean' or 'spherical' determining the metric used for clustering

doPlot

logical: Would you like to see the elbow plot to determine the number of clusters?

num.clusters

set of values for number of clusters to test.

bnc_threshold

Specifies the threshold for reduction ratio in within group sum of squares

Value

list: containing three elements: wgss (Within group sum of squares), clst (list of clustering objects), bnc(best number of clusters)

Examples

a = elbow(iris[,1:4], num.clusters = c(2, 5, 10, 15, 20, 25), doPlot = T)

a$wgss
      NC2       NC5      NC10      NC15      NC20      NC25 
152.34795  46.46117  29.90776  21.67031  17.78198  11.90241 
(Your values may be different!)

a$clst[[a$bnc]]$cluster %>% table
1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 
15 10  7 13  8  8  1 10  4  6  3  5  8  9  5  5  5 14 10  4 
(Your values may be different!)

genpack/gener documentation built on Jan. 27, 2025, 1:07 a.m.