[scikit-learn] Drawing contours in KMeans

Andrew Howe ahowe42 at gmail.com
Wed Dec 9 14:22:30 EST 2020


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

<~~~~~~~~~~~~~~~~~~~~~~~~~~~>
J. Andrew Howe, PhD
LinkedIn Profile <http://www.linkedin.com/in/ahowe42>
ResearchGate Profile <http://www.researchgate.net/profile/John_Howe12/>
Open Researcher and Contributor ID (ORCID)
<http://orcid.org/0000-0002-3553-1990>
Github Profile <http://github.com/ahowe42>
Personal Website <http://www.andrewhowe.com>
I live to learn, so I can learn to live. - me
<~~~~~~~~~~~~~~~~~~~~~~~~~~~>


On Wed, Dec 9, 2020 at 12:59 PM Mahmood Naderan <mahmood.nt at gmail.com>
wrote:

> 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 <ahowe42 at gmail.com> wrote:
>
>> 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 <http://www.linkedin.com/in/ahowe42>
>> ResearchGate Profile <http://www.researchgate.net/profile/John_Howe12/>
>> Open Researcher and Contributor ID (ORCID)
>> <http://orcid.org/0000-0002-3553-1990>
>> Github Profile <http://github.com/ahowe42>
>> Personal Website <http://www.andrewhowe.com>
>> I live to learn, so I can learn to live. - me
>> <~~~~~~~~~~~~~~~~~~~~~~~~~~~>
>>
>>
>> On Wed, Dec 9, 2020 at 9:41 AM Mahmood Naderan <mahmood.nt at gmail.com>
>> wrote:
>>
>>> 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_[:,
>>> 1], s=100, c='red')
>>> plt.show()
>>>
>>> I would like to know if it is possible to draw contours over the
>>> clusters. Is there any way for that?
>>> Please let me know if there is a function or option in KMeans.
>>>
>>> Regards,
>>> Mahmood
>>>
>>>
>>> _______________________________________________
>>> scikit-learn mailing list
>>> scikit-learn at python.org
>>> https://mail.python.org/mailman/listinfo/scikit-learn
>>>
>> _______________________________________________
>> scikit-learn mailing list
>> scikit-learn at python.org
>> https://mail.python.org/mailman/listinfo/scikit-learn
>>
> _______________________________________________
> scikit-learn mailing list
> scikit-learn at python.org
> https://mail.python.org/mailman/listinfo/scikit-learn
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/pipermail/scikit-learn/attachments/20201209/8ea56d53/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 44525 bytes
Desc: not available
URL: <https://mail.python.org/pipermail/scikit-learn/attachments/20201209/8ea56d53/attachment-0001.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: KMeans_Cluster_Circle.ipynb
Type: application/octet-stream
Size: 27501 bytes
Desc: not available
URL: <https://mail.python.org/pipermail/scikit-learn/attachments/20201209/8ea56d53/attachment-0001.obj>


More information about the scikit-learn mailing list