Seaborn: Seaborn's clustermap uses fastcluster, but not in dependencies

Created on 5 Feb 2018  路  13Comments  路  Source: mwaskom/seaborn

Title says it all. Ran sns.clustermap earlier and got

Traceback (most recent call last):
  File "/home/users/fgrandi/.miniconda3/lib/python3.6/site-packages/seaborn/matrix.py", line 626, in calculated_linkage
    return self._calculate_linkage_fastcluster()
  File "/home/users/fgrandi/.miniconda3/lib/python3.6/site-packages/seaborn/matrix.py", line 607, in _calculate_linkage_fastcluster
    import fastcluster
ModuleNotFoundError: No module named 'fastcluster'

Is there a reason for this or should I submit a PR with that module added to setup.py?

Most helpful comment

I have the same error, with fastcluster throwing a ModuleNotFoundError and not falling back to scipy. Downloading fastcluster as well.

All 13 comments

Can you show a full example of what you're doing? If fastcluster is not installed it should just fall back to scipy, potentially issuing a warning if you're trying to cluster a particularly large matrix.

Closing for lack of information.

I think the problem is in Python 3.6 the error raised is no longer ImportError but ModuleNotFoundError so the try/catch doesn't catch the new error.

ModuleNotFoundError is a subclass of ImportError and so should be caught: https://airbrake.io/blog/python/importerror-and-modulenotfounderror

I've just confirmed that on my system I can use clustermap with no problems in a Python 3.6 environment that does not have fastcluster installed (trying to import raises a ModuleNotFoundError) so if this problem exists it's not general.

I also found this error. Could only fix it by installing the fastcluster package.

I have the same error, with fastcluster throwing a ModuleNotFoundError and not falling back to scipy. Downloading fastcluster as well.

If we need fastcluster for clustermap, should this package be added into requirements.txt?

Can confirm the issue on Ubuntu 18.04 in a virtualenv.

I suspect that people are getting errors during clustering and seeing the fastcluster exception because it is part of the stack trace (it gets caught and then the code moves on to use scipy), but it is not the actual cause of their problem. However, nobody has provided sufficient information to provide help beyond speculation.

I got this error when running sns.clustermap out of the box. It did not result in a graph, just the error. Was in a jupyter notebook. sns.heatmap worked just fine. As far as I can see it does not fall back to scipy.

Encountered this error message and at least in my case, the error is trigger when the data matrix has one or more column(s) or row(s) full of zeros. Here's the trace and how to reproduce:

To reproduce, simply:
import numpy as np
import seaborn as sns
matrix = np.random.rand(10, 100)
matrix[0, :] = 0
sns.clustermap(matrix, metric='cosine', method='single')
plt.show()

Trace back: https://pastebin.com/fb1QngyS

Thank you for providing a reproducible example. But the problem here is not the absence of fastcluster. As I said, that is caught and handled, and then you鈥檙e getting an exception from inside the scipy clustering code.

I encountered the same error as well. Mine was caused by NaN values in the matrix I was using. Changing that solved the problem. I thought it may help people arriving at this page looking for answers.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sungshine picture sungshine  路  3Comments

stonebig picture stonebig  路  4Comments

Bercio picture Bercio  路  3Comments

songololo picture songololo  路  4Comments

wenhaosun picture wenhaosun  路  3Comments