[scikit-learn] KMeans with cosine similarity

Joel Nothman joel.nothman at gmail.com
Thu Jun 2 20:36:07 EDT 2016


In short, no, monkey patching cosine_similarity in place of
euclidean_distances will not work. See for instance this StackOverflow
post:
http://stats.stackexchange.com/questions/81481/why-does-k-means-clustering-algorithm-use-only-euclidean-distance-metric

You could try out this Kernel KMeans implementation:
https://github.com/scikit-learn/scikit-learn/pull/5483

On 3 June 2016 at 05:24, JAGANADH G <jaganadhg at gmail.com> wrote:

> Hi Team,
> I was trying to use cosine similarity with KMeans. The code which I used
> to achieve is available here.
> https://gist.github.com/jaganadhg/b3f6af86ad99bf6e9bb7be21e5baa1b5
>
> Is it the right way to achieve the same ? I know that cosine is not
> directly supported in sklearn KMeans. But after skimming through the code I
> was thinking that this will work ;-)
>
> --
> **********************************
> JAGANADH G
> http://jaganadhg.in
> *ILUGCBE*
> http://ilugcbe.org.in
>
> _______________________________________________
> 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: <http://mail.python.org/pipermail/scikit-learn/attachments/20160603/039565ff/attachment.html>


More information about the scikit-learn mailing list