> For the complete documentation index, see [llms.txt](https://ykkim.gitbook.io/wiki/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ykkim.gitbook.io/wiki/machine-learning/lecture-notes/clustering.md).

# Clustering

## K-means

![100 pages machine learning](https://3698175758-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MAwtzMy_pbrChIExFtN%2Fuploads%2Fgit-blob-3274a6d63c010c02bef100e9e812275e7dc547ed%2Fimage.png?alt=media)

![](https://3698175758-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MAwtzMy_pbrChIExFtN%2Fuploads%2Fgit-blob-b29ddf51ff8acc28b5979b273ecc9cdf92e8434d%2Fimage.png?alt=media)

![](https://3698175758-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MAwtzMy_pbrChIExFtN%2Fuploads%2Fgit-blob-6f8e9867c5f7f46acdc925841eb70f5d3c902106%2Fimage.png?alt=media)

### Optimization of K-Means

![](https://3698175758-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MAwtzMy_pbrChIExFtN%2Fuploads%2Fgit-blob-07a05bfcb3ab46724cb15cd6c4abab4138724b18%2Fimage.png?alt=media)

![](https://3698175758-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MAwtzMy_pbrChIExFtN%2Fuploads%2Fgit-blob-eeef3e8244ae3942939c4018d16f45e7c66baaad%2Fimage.png?alt=media)

### How to choose k ?

The value of k, the number of clusters, is a hyperparameter that has to be tuned by the data analyst. There are some techniques for selecting k. None of them is proven optimal. Most of those techniques require the analyst to make an “educated guess” by looking at some metrics or by examining cluster assignments visually.

Methods

* Prediction Strength (See 9.2.3 \[1] )
* Gap statistic method
* Elbow method
* Average silihouette method

## Referene

\[1] The Hundred-Page Machine Learning Book <http://themlbook.com/wiki/doku.php>

\[2] Machine Learning, Huang, VTech
