# Get WCSS (Within-Cluster Sum of Square) for optimal number of clusters in kmeans

**URL:** <https://discourse.julialang.org/t/get-wcss-within-cluster-sum-of-square-for-optimal-number-of-clusters-in-kmeans/90374>\
**Category:** Statistics\
**Tags:** statistics, cluster, machine-learning, clustering\
**Created:** [November 16, 2022, 11:34pm UTC](https://discourse.julialang.org/t/get-wcss-within-cluster-sum-of-square-for-optimal-number-of-clusters-in-kmeans/90374 "2022-11-16T23:34:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![indymnv](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/indymnv/32/212594_2.png) [@indymnv](https://discourse.julialang.org/u/indymnv)\
**Post date:** [November 16, 2022, 11:34pm UTC](https://discourse.julialang.org/t/get-wcss-within-cluster-sum-of-square-for-optimal-number-of-clusters-in-kmeans/90374/1 "2022-11-16T23:34:40Z")

</div>

I want to use kmeans for a clustering project, and I need to get the optimal number of clusters with the elbow method, is there a way to get the WCSS in the implementation of [Clustering.jl](https://juliastats.org/Clustering.jl/dev/kmeans.html) to build something like this

 ![elbow](https://global.discourse-cdn.com/julialang/original/3X/a/2/a28bf16d7058703590fc962a0ad67a38f9018878.png)

the dataset could be like the typical iris

```julia
using RDatasets, Clustering, Plots
iris = dataset("datasets", "iris"); # load the data

```
