[SciPy-User] Use Distance Matrix in scipy.cluster.hierarchy.linkage()?

Kevin Gullikson kevin.gullikson at gmail.com
Fri Feb 24 09:50:23 EST 2017


Sema,

It is a two step process (at least). Here is an example:

    from scipy.cluster import hierarchy

    Z = hierarchy.linkage(dm, metric='precomputed')
    labels = hierarchy.fcluster(Z, n_clusters, criterion='maxclust')

The labels array will have length n, and will look like [0, 0, 1, 2, 0,
...]. Typically, you have to choose the number of clusters (or some other
criterion, see fcluster docs). You can do that by looking at the dendrogram
plot with this command, which will make a matplotlib plot:

    hierarchy.dendrogram(Z)  # This has a bunch of useful keyword arguments
too.

Happy clustering!
Kevin

On Fri, Feb 24, 2017 at 12:59 AM Sema Atasever <s.atasever at gmail.com> wrote:

> Dear SciPy list member,
>
> I want to ask you about clustering usign scipy.cluster.hierarchy.
>
> I have a *distance matrix* n*n M where M_ij is the distance between
> object_i and object_j. You can see file format in the attachment -->
> (dm.csv)
>
> I want to cluster these n objects with hierarchical clustering.
>
> For this purpose i am usign this python code that you can see in the
> attachment (scipy_code.py)
>
> I want to ask that how can get clusters values in pdf format or text
> format and how many clusters did i get and what clusters includes what
> members?
>
> Thanks in Advance, Best regards.
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at python.org
> https://mail.python.org/mailman/listinfo/scipy-user
>
-- 
Kevin Gullikson
Data Scientist
Spark Cognition
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scipy-user/attachments/20170224/657874c4/attachment.html>


More information about the SciPy-User mailing list