Answers.Body: <p>If you look at Kaufman &amp; Rousseeuw (1990), <em><a href="https://onlinelibrary.wiley.com/doi/book/10.1002/9780470316801" rel="nofollow noreferrer">Finding Groups in Data</a></em>, they describe an algorithm to evaluate the quality of clusters in agglomerative clustering. You run the clustering algorithm with a specific value <em>k</em> for the number of clusters you want, and that routine then gives you a score to reflect the cohesion of the clustering. If you then cluster again with a different value for <em>k</em>, you will get another score. You repeat this process until you have found a maximum score, and then you have the clustering with the optimum number of clusters.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-07-01T18:18:55.160Z
Answers.LastActivityDate: 2019-07-01T18:18:55.160Z
Answers.UserDisplayName: Oliver Mason
Answers.Body: <p>Yes, the <a href="https://en.wikipedia.org/wiki/Silhouette_(clustering)" rel="nofollow noreferrer">silhouette</a> method (which is implemented in <code>sklearn</code> as <a href="https://scikit-learn.org/stable/modules/generated/sklearn.metrics.silhouette_score.html" rel="nofollow noreferrer"><code>silhouette_score</code></a>) is commonly used to assess the quality of clusters produced by any clustering algorithm (including <span class="math-container">$k$</span>-means or any hierarchical clustering algorithm). Roughly, you can compute the silhouette value for different <span class="math-container">$k$</span>, then you would pick the <span class="math-container">$k$</span> with the highest silhouette value.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-07-02T08:02:01.213Z
Answers.Text: Yes, I think that's the one I talk about in my answer -- I forgot the name, as it has been a while :)
Answers.UserDisplayName: Oliver Mason
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-07-01T18:45:40.753Z
Answers.LastActivityDate: 2019-07-01T18:45:40.753Z
Answers.UserDisplayName: nbro
Body: <p>I need to cluster my points into unknown number of clusters, given the minimal Euclidean distance R between the two clusters. Any two clusters that are closer than this minimal distance should be merged and treated as one.</p>
  
  <p>I could implement a loop starting from the two clusters and going up until I observe the pair of clusters that are closer to each other than my minimal distance. The upper boundary of the loop is the number of points we need to cluster.</p>
  
  <p>Are there any well known algorithms and approaches estimate the approximate number of centroids from the set of points and required minimal distance between centroids?</p>
  
  <p>I am currently using FAISS under Python, but with the right idea I could also implement in C myself.</p>
  
Tags: <machine-learning><k-means><clustering>
Title: How to compute the number of centroids for K-means clustering algorithm given minimal distance?
UserDisplayName: h22
ThreadText: # How to compute the number of centroids for K-means clustering algorithm given minimal distance?
  
  (Asked by: username_0 on 2019-07-01)
  
  I need to cluster my points into unknown number of clusters, given the minimal Euclidean distance R between the two clusters. Any two clusters that are closer than this minimal distance should be merged and treated as one.
  
  I could implement a loop starting from the two clusters and going up until I observe the pair of clusters that are closer to each other than my minimal distance. The upper boundary of the loop is the number of points we need to cluster.
  
  Are there any well known algorithms and approaches estimate the approximate number of centroids from the set of points and required minimal distance between centroids?
  
  I am currently using FAISS under Python, but with the right idea I could also implement in C myself.
  
  **Tags:** machine-learning, k-means, clustering
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2019-07-01. Score: 3 | Accepted answer
  
  Yes, the [silhouette](https://en.wikipedia.org/wiki/Silhouette_(clustering)) method (which is implemented in `sklearn` as [`silhouette_score`](https://scikit-learn.org/stable/modules/generated/sklearn.metrics.silhouette_score.html)) is commonly used to assess the quality of clusters produced by any clustering algorithm (including $k$-means or any hierarchical clustering algorithm). Roughly, you can compute the silhouette value for different $k$, then you would pick the $k$ with the highest silhouette value.
  
  > **Comments:**
  > **username_1**: Yes, I think that's the one I talk about in my answer -- I forgot the name, as it has been a while :)  
  
  ---
  
  ### Answer by username_1 on 2019-07-01. Score: 1
  
  If you look at Kaufman & Rousseeuw (1990), *[Finding Groups in Data](https://onlinelibrary.wiley.com/doi/book/10.1002/9780470316801)*, they describe an algorithm to evaluate the quality of clusters in agglomerative clustering. You run the clustering algorithm with a specific value *k* for the number of clusters you want, and that routine then gives you a score to reflect the cohesion of the clustering. If you then cluster again with a different value for *k*, you will get another score. You repeat this process until you have found a maximum score, and then you have the clustering with the optimum number of clusters.
  
  
  ---
  
  