<div dir="ltr"><div>Dear Mahmood,</div><div><br></div><div>Andrew's solution with a circle will guarantee you render an image in which every point is covered within some circle.</div><div><br></div><div>However, if data contains outliers or artifacts, you might get circles which are excessively large and distort the image you want.</div><div>For example, imagine if there were a single red point in Andrew's image at the coordinate (3,10); then, the resulting circle would cover all points in the entire plot, which is unlikely what you want.</div><div>You could potentially generate a density estimate for each class and then have matplotlib render the contour lines (e.g., solutions of where estimates have a specific value), but as was said, this is not the job of Kmeans, but rather of general data analysis.</div><div><br></div><div>The ellipsoid solution proposed to you is, in a sense, a middle ground between these two solutions (the circles and the density plots).</div><div>You could adjust the (4 or 5) parameters of an ellipsoid to cover "most" of the points for a particular class and tolerate that the ellipsoids don't cover a few outliers or artifacts (e.g., the coordinate (3,10) I mentioned above).</div>The resulting functional forms of the ellipses might be more precise than circles and less complex than density contours, and might lead to actionable knowledge depending on your context/domain.<br><div><div><br></div><div>Hope this helps.</div><div>J.B. Brown<br></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">2020年12月9日(水) 21:08 Mahmood Naderan <<a href="mailto:mahmood.nt@gmail.com">mahmood.nt@gmail.com</a>>:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_default" style="font-family:tahoma,sans-serif">
<div style="font-family:bookman old style,new york,times,serif;font-size:16px" dir="ltr">>Mebbe principal components analysis would suggest an <br></div><div style="font-family:bookman old style,new york,times,serif;font-size:16px" dir="ltr">>ellipsoid containing "most" of the points in a "cloud".</div>

</div><div><div dir="ltr"><div dir="ltr"><font face="tahoma,sans-serif"><br></font></div>S<span class="gmail_default" style="font-family:tahoma,sans-serif">orry I didn't understand. Can you explain more?</span></div><div dir="ltr"><span class="gmail_default" style="font-family:tahoma,sans-serif"></span><div dir="ltr"><font face="tahoma,sans-serif">Regards,<br>Mahmood</font><br><br><br></div></div></div><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Dec 9, 2020 at 8:55 PM The Helmbolds via scikit-learn <<a href="mailto:scikit-learn@python.org" target="_blank">scikit-learn@python.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div style="font-family:bookman old style,new york,times,serif;font-size:16px" dir="ltr"><span><span style="text-align:left;color:rgb(29,34,40);text-transform:none;text-indent:0px;letter-spacing:normal;font-family:YahooSans,Helvetica Neue,Segoe UI,Helvetica,Arial,Lucida Grande,sans-serif;font-size:17px;font-style:normal;font-variant:normal;font-weight:400;text-decoration:none;word-spacing:0px;white-space:normal">[scikit-learn] Drawing contours in KMeans</span><span style="font:400 11px/18px YahooSans,Helvetica Neue,Segoe UI,Helvetica,Arial,Lucida Grande,sans-serif;padding:0px 6px;border-radius:9px;text-align:left;color:rgb(29,34,40);text-transform:none;text-indent:0px;letter-spacing:normal;text-decoration:none;margin-right:6px;margin-left:8px;word-spacing:0px;display:inline-block;white-space:normal;background-color:rgb(224,228,233)">4</span></span></div><div style="font-family:bookman old style,new york,times,serif;font-size:16px" dir="ltr"><b></b><i></i><u></u><sub></sub><sup></sup><strike></strike><br></div><div style="font-family:bookman old style,new york,times,serif;font-size:16px" dir="ltr"><br></div><div style="font-family:bookman old style,new york,times,serif;font-size:16px" dir="ltr">Mebbe principal components analysis would suggest an ellipsoid containing "most" of the points in a "cloud".</div><div style="font-family:bookman old style,new york,times,serif;font-size:16px" dir="ltr"><br></div><div style="font-family:bookman old style,new york,times,serif;font-size:16px" dir="ltr"><br></div><div style="font-family:bookman old style,new york,times,serif;font-size:16px" dir="ltr"><br></div><div style="font-family:bookman old style,new york,times,serif;font-size:16px"><b></b><i></i><u></u><sub></sub><sup></sup><strike></strike><br></div><div style="font-family:bookman old style,new york,times,serif;font-size:16px">"You won't find the right answers if you don't ask the right questions!" (Robert Helmbold, 2013)</div><div style="font-family:bookman old style,new york,times,serif;font-size:16px">
        </div><div style="font-family:bookman old style,new york,times,serif;font-size:16px"><br></div><div style="font-family:bookman old style,new york,times,serif;font-size:16px"><br></div><div style="font-family:bookman old style,new york,times,serif;font-size:16px">
        
        </div><div id="gmail-m_-4323305516444331005gmail-m_-3762925116539474070yahoo_quoted_8036565211">
            <div style="font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px;color:rgb(38,40,42)">
                
                <div>
                    On Wednesday, December 9, 2020, 12:22:49 PM MST, Andrew Howe <<a href="mailto:ahowe42@gmail.com" target="_blank">ahowe42@gmail.com</a>> wrote:
                </div>
                <div><br></div>
                <div><br></div>
                <div><div id="gmail-m_-4323305516444331005gmail-m_-3762925116539474070yiv8368675567"><div><div dir="ltr">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.<div><img style="margin-right: 0px;" alt="image.png" src="cid:176491c43dccb971f161" width="224" height="146"><br clear="none"></div><div>Andrew</div><div><br clear="all"><div><div dir="ltr"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><~~~~~~~~~~~~~~~~~~~~~~~~~~~><br clear="none">J. Andrew Howe, PhD</div><div dir="ltr"><a href="http://www.linkedin.com/in/ahowe42" rel="nofollow" shape="rect" target="_blank">LinkedIn Profile</a></div><div><a href="http://www.researchgate.net/profile/John_Howe12/" rel="nofollow" shape="rect" target="_blank">ResearchGate Profile</a></div><div dir="ltr"><a href="http://orcid.org/0000-0002-3553-1990" rel="nofollow" shape="rect" target="_blank">Open Researcher and Contributor ID (ORCID)</a></div><div dir="ltr"><a href="http://github.com/ahowe42" rel="nofollow" shape="rect" target="_blank">Github Profile</a><br clear="none"><div><a href="http://www.andrewhowe.com" rel="nofollow" shape="rect" target="_blank">Personal Website</a></div><div>I live to learn, so I can learn to live. - me<br clear="none"></div><div><~~~~~~~~~~~~~~~~~~~~~~~~~~~></div></div></div></div></div></div></div></div><br clear="none"></div></div><br clear="none"><div><div id="gmail-m_-4323305516444331005gmail-m_-3762925116539474070yiv8368675567yqtfd11384"><div dir="ltr">On Wed, Dec 9, 2020 at 12:59 PM Mahmood Naderan <<a href="mailto:mahmood.nt@gmail.com" rel="nofollow" shape="rect" target="_blank">mahmood.nt@gmail.com</a>> wrote:<br clear="none"></div><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div style="font-family:tahoma,sans-serif">I mean a circle/contour to group the points in a cluster for better representation. <br clear="none"></div><div style="font-family:tahoma,sans-serif">For example, if there are 6 six clusters, it will be more meaningful to group large data points in a circle or contour.</div><div style="font-family:tahoma,sans-serif"><br clear="all"></div><div><div dir="ltr"><div dir="ltr"><font face="tahoma,sans-serif">Regards,<br clear="none">Mahmood</font><br clear="none"><br clear="none"><br clear="none"></div></div></div><br clear="none"></div><br clear="none"><div><div dir="ltr">On Wed, Dec 9, 2020 at 11:49 AM Andrew Howe <<a href="mailto:ahowe42@gmail.com" rel="nofollow" shape="rect" target="_blank">ahowe42@gmail.com</a>> wrote:<br clear="none"></div><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">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?<div><br clear="none"></div><div>Andrew<div><br clear="all"><div><div dir="ltr"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><~~~~~~~~~~~~~~~~~~~~~~~~~~~><br clear="none">J. Andrew Howe, PhD</div><div dir="ltr"><a href="http://www.linkedin.com/in/ahowe42" rel="nofollow" shape="rect" target="_blank">LinkedIn Profile</a></div><div><a href="http://www.researchgate.net/profile/John_Howe12/" rel="nofollow" shape="rect" target="_blank">ResearchGate Profile</a></div><div dir="ltr"><a href="http://orcid.org/0000-0002-3553-1990" rel="nofollow" shape="rect" target="_blank">Open Researcher and Contributor ID (ORCID)</a></div><div dir="ltr"><a href="http://github.com/ahowe42" rel="nofollow" shape="rect" target="_blank">Github Profile</a><br clear="none"><div><a href="http://www.andrewhowe.com" rel="nofollow" shape="rect" target="_blank">Personal Website</a></div><div>I live to learn, so I can learn to live. - me<br clear="none"></div><div><~~~~~~~~~~~~~~~~~~~~~~~~~~~></div></div></div></div></div></div></div></div><br clear="none"></div></div></div><br clear="none"><div><div dir="ltr">On Wed, Dec 9, 2020 at 9:41 AM Mahmood Naderan <<a href="mailto:mahmood.nt@gmail.com" rel="nofollow" shape="rect" target="_blank">mahmood.nt@gmail.com</a>> wrote:<br clear="none"></div><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div style="font-family:tahoma,sans-serif">Hi</div><div style="font-family:tahoma,sans-serif">I use the following code to highlight the cluster centers with some red dots.</div><div style="font-family:tahoma,sans-serif"><br clear="none"></div><div style="font-family:tahoma,sans-serif">kmeans = KMeans(n_clusters=6, init='k-means++', max_iter=100, n_init=10, random_state=0)<br clear="none">pred_y = kmeans.fit_predict(a)<br clear="none">plt.scatter(a[:,0], a[:,1])<br clear="none">plt.scatter(kmeans.cluster_centers_[:, 0], kmeans.cluster_centers_[:, 1], s=100, c='red')<br clear="none">plt.show()<br clear="none"></div><div style="font-family:tahoma,sans-serif"><br clear="none"></div><div style="font-family:tahoma,sans-serif">I would like to know if it is possible to draw contours over the clusters. Is there any way for that?</div><div style="font-family:tahoma,sans-serif">Please let me know if there is a function or option in KMeans.</div><div style="font-family:tahoma,sans-serif"><br clear="all"></div><div><div dir="ltr"><div dir="ltr"><font face="tahoma,sans-serif">Regards,<br clear="none">Mahmood</font><br clear="none"><br clear="none"><br clear="none"></div></div></div></div>
_______________________________________________<br clear="none">
scikit-learn mailing list<br clear="none">
<a href="mailto:scikit-learn@python.org" rel="nofollow" shape="rect" target="_blank">scikit-learn@python.org</a><br clear="none">
<a href="https://mail.python.org/mailman/listinfo/scikit-learn" rel="nofollow" shape="rect" target="_blank">https://mail.python.org/mailman/listinfo/scikit-learn</a><br clear="none">
</blockquote></div>
_______________________________________________<br clear="none">
scikit-learn mailing list<br clear="none">
<a href="mailto:scikit-learn@python.org" rel="nofollow" shape="rect" target="_blank">scikit-learn@python.org</a><br clear="none">
<a href="https://mail.python.org/mailman/listinfo/scikit-learn" rel="nofollow" shape="rect" target="_blank">https://mail.python.org/mailman/listinfo/scikit-learn</a><br clear="none">
</blockquote></div>
_______________________________________________<br clear="none">
scikit-learn mailing list<br clear="none">
<a href="mailto:scikit-learn@python.org" rel="nofollow" shape="rect" target="_blank">scikit-learn@python.org</a><br clear="none">
<a href="https://mail.python.org/mailman/listinfo/scikit-learn" rel="nofollow" shape="rect" target="_blank">https://mail.python.org/mailman/listinfo/scikit-learn</a><br clear="none">
</blockquote></div></div></div></div><div id="gmail-m_-4323305516444331005gmail-m_-3762925116539474070yqtfd35235">_______________________________________________<br clear="none">scikit-learn mailing list<br clear="none"><a href="mailto:scikit-learn@python.org" shape="rect" target="_blank">scikit-learn@python.org</a><br clear="none"><a href="https://mail.python.org/mailman/listinfo/scikit-learn" shape="rect" target="_blank">https://mail.python.org/mailman/listinfo/scikit-learn</a><br clear="none"></div></div>
            </div>
        </div></div>_______________________________________________<br>
scikit-learn mailing list<br>
<a href="mailto:scikit-learn@python.org" target="_blank">scikit-learn@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/scikit-learn" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/scikit-learn</a><br>
</blockquote></div>
_______________________________________________<br>
scikit-learn mailing list<br>
<a href="mailto:scikit-learn@python.org" target="_blank">scikit-learn@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/scikit-learn" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/scikit-learn</a><br>
</blockquote></div>