Answers.Body: <p>So, I've prepared some data that resembles your sketch:</p>
  <pre><code>n , u = np.random.normal , np.random.uniform
  x = np.concatenate([ n(1.0,0.2,100), n(3.0,0.3,100), u(0,10.0,100)])
  y = np.concatenate([ n(7.0,0.4,100), n(5.0,0.3,100), u(0,10.0,100)])
  # lets shuffle it a bit
  idx = np.arange(x.shape[0])
  np.random.shuffle(idx)
  data = np.array([x,y])[:,idx]
  </code></pre>
  <p><a href="https://i.sstatic.net/S1zve.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/S1zve.png" alt="enter image description here" /></a></p>
  <p>And then I just tried using <code>sklearn.mixture.GaussianMixture</code> with n+1 = 3 components and default parameters:</p>
  <pre><code>gmm = GaussianMixture(n_components=3).fit(data.T)
  cls = gmm.predict_proba(data.T).argmax(axis=1)
  
  # Plotting
  color = [['r','k','g'][i] for i in cls]
  scatter(data[0],data[1],c=color, marker='.')
  scatter(gmm.means_[:,0],gmm.means_[:,1],c='b',marker='o')
  </code></pre>
  <p><a href="https://i.sstatic.net/CQjDd.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/CQjDd.png" alt="enter image description here" /></a></p>
  <p>That seems awfully lot like the thing you've sketched.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-05-09T04:04:16.427Z
Answers.Text: Nice demonstration of what Gaussian  mixture models can be used for!
Answers.UserDisplayName: Mike NZ
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-04-08T22:04:37.760Z
Answers.LastActivityDate: 2021-04-08T22:04:37.760Z
Answers.UserDisplayName: Kostya
Body: <p>As far as I know all clustering algorithms assume that all delivered data points have to find its cluster.</p>
  <p>My question is, is there an algorithm that could focus only on n clusters (number stated by user) and try to dismiss the rest of the points that (according to algorithm) do not belong to n clusters, like in the picture shown below? Where we know that there are for example 2 classes that we need to cluster (red and green) and the rest (blue) we do not need in any cluster and therefore algorithm does not try to assign them to any cluster?</p>
  <p>For example if we would have 1 000 pictures of animals, of which 200 are dogs, 200 are cats and the rest are all other animals known to men and we want to make 1 cluster for cats, 1 for dogs and maybe another for collectively all others that do not match dogs or cats.</p>
  <p><a href="https://i.sstatic.net/zS0D6.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/zS0D6.png" alt="enter image description here" /></a></p>
  
Tags: <unsupervised-learning><data-science><clustering>
Title: Is there a clustering algorithm that can make n clusters and the n+1 "others" cluster?
UserDisplayName: GKozinski
ThreadText: # Is there a clustering algorithm that can make n clusters and the n+1 "others" cluster?
  
  (Asked by: username_0 on 2021-04-08)
  
  As far as I know all clustering algorithms assume that all delivered data points have to find its cluster.
  
  My question is, is there an algorithm that could focus only on n clusters (number stated by user) and try to dismiss the rest of the points that (according to algorithm) do not belong to n clusters, like in the picture shown below? Where we know that there are for example 2 classes that we need to cluster (red and green) and the rest (blue) we do not need in any cluster and therefore algorithm does not try to assign them to any cluster?
  
  For example if we would have 1 000 pictures of animals, of which 200 are dogs, 200 are cats and the rest are all other animals known to men and we want to make 1 cluster for cats, 1 for dogs and maybe another for collectively all others that do not match dogs or cats.
  
  [![enter image description here](https://i.sstatic.net/zS0D6.png)](https://i.sstatic.net/zS0D6.png)
  
  **Tags:** unsupervised-learning, data-science, clustering
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-04-08. Score: 1
  
  So, I've prepared some data that resembles your sketch:
  
  ```
  n , u = np.random.normal , np.random.uniform
  x = np.concatenate([ n(1.0,0.2,100), n(3.0,0.3,100), u(0,10.0,100)])
  y = np.concatenate([ n(7.0,0.4,100), n(5.0,0.3,100), u(0,10.0,100)])
  # lets shuffle it a bit
  idx = np.arange(x.shape[0])
  np.random.shuffle(idx)
  data = np.array([x,y])[:,idx]
  
  ```
  
  [![enter image description here](https://i.sstatic.net/S1zve.png)](https://i.sstatic.net/S1zve.png)
  
  And then I just tried using `sklearn.mixture.GaussianMixture` with n+1 = 3 components and default parameters:
  
  ```
  gmm = GaussianMixture(n_components=3).fit(data.T)
  cls = gmm.predict_proba(data.T).argmax(axis=1)
  
  # Plotting
  color = [['r','k','g'][i] for i in cls]
  scatter(data[0],data[1],c=color, marker='.')
  scatter(gmm.means_[:,0],gmm.means_[:,1],c='b',marker='o')
  
  ```
  
  [![enter image description here](https://i.sstatic.net/CQjDd.png)](https://i.sstatic.net/CQjDd.png)
  
  That seems awfully lot like the thing you've sketched.
  
  > **Comments:**
  > **username_2**: Nice demonstration of what Gaussian  mixture models can be used for!  
  
  ---
  
  