Re: [scikit-learn] Drawing contours in KMeans

2020-12-09 Thread Abhishek Ghose
Sorry, just noticed that I had forgotten to attach a sample image. Regards On Wed, Dec 9, 2020 at 1:21 PM Abhishek Ghose wrote: > Hi, > > A quick way I use is to draw a convex hull (scipy) around the points in a > cluster. > Here's a short example - k-means with k=2 is run on synthetic data: >

Re: [scikit-learn] Drawing contours in KMeans

2020-12-09 Thread Abhishek Ghose
Hi, A quick way I use is to draw a convex hull (scipy) around the points in a cluster. Here's a short example - k-means with k=2 is run on synthetic data: from sklearn.datasets import make_blobs from sklearn.cluster import KMeans from matplotlib import pyplot as plt from scipy.spatial import Conv

Re: [scikit-learn] Drawing contours in KMeans

2020-12-09 Thread Brown J.B. via scikit-learn
Dear Mahmood, Andrew's solution with a circle will guarantee you render an image in which every point is covered within some circle. However, if data contains outliers or artifacts, you might get circles which are excessively large and distort the image you want. For example, imagine if there wer

Re: [scikit-learn] Drawing contours in KMeans

2020-12-09 Thread Mahmood Naderan
>Mebbe principal components analysis would suggest an >ellipsoid containing "most" of the points in a "cloud". Sorry I didn't understand. Can you explain more? Regards, Mahmood On Wed, Dec 9, 2020 at 8:55 PM The Helmbolds via scikit-learn < scikit-learn@python.org> wrote: > [scikit-learn] Dr

Re: [scikit-learn] Drawing contours in KMeans

2020-12-09 Thread The Helmbolds via scikit-learn
[scikit-learn] Drawing contours in KMeans4 Mebbe principal components analysis would suggest an ellipsoid containing "most" of the points in a "cloud". "You won't find the right answers if you don't ask the right questions!" (Robert Helmbold, 2013) On Wednesday, December 9, 2020, 12:22:

Re: [scikit-learn] Drawing contours in KMeans

2020-12-09 Thread Andrew Howe
Ok, I see. Well the attached notebook demonstrates doing this by simply finding the maximum distance from each centroid to it's datapoints and drawing a circle using that radius. It's simple, but will hopefully at least point you in a useful direction. [image: image.png] Andrew <~~

Re: [scikit-learn] Drawing contours in KMeans

2020-12-09 Thread Mahmood Naderan
I mean a circle/contour to group the points in a cluster for better representation. For example, if there are 6 six clusters, it will be more meaningful to group large data points in a circle or contour. Regards, Mahmood On Wed, Dec 9, 2020 at 11:49 AM Andrew Howe wrote: > Contours generally

Re: [scikit-learn] Drawing contours in KMeans

2020-12-09 Thread Andrew Howe
Contours generally indicate a third variable - often a probability density. Kmeans doesn't provide density estimates, so what precisely would you want the contours to represent? Andrew <~~~> J. Andrew Howe, PhD LinkedIn Profile Research

[scikit-learn] Drawing contours in KMeans

2020-12-09 Thread Mahmood Naderan
Hi I use the following code to highlight the cluster centers with some red dots. kmeans = KMeans(n_clusters=6, init='k-means++', max_iter=100, n_init=10, random_state=0) pred_y = kmeans.fit_predict(a) plt.scatter(a[:,0], a[:,1]) plt.scatter(kmeans.cluster_centers_[:, 0], kmeans.cluster_centers_[:,