umap: AttributeError: module 'scipy.sparse' has no attribute 'csgraph'

Hello,

Thank you for the great contribution.

I can’t seem to get it running. Any help is appreciated.

Here are my versions:

Requirement already satisfied: umap-learn in ./anaconda3/lib/python3.6/site-packages
Requirement already satisfied: numba>=0.34 in ./anaconda3/lib/python3.6/site-packages (from umap-learn)
Requirement already satisfied: scipy>=0.19 in ./anaconda3/lib/python3.6/site-packages (from umap-learn)
Requirement already satisfied: scikit-learn>=0.16 in ./anaconda3/lib/python3.6/site-packages (from umap-learn)
Requirement already satisfied: llvmlite in ./anaconda3/lib/python3.6/site-packages (from numba>=0.34->umap-learn)
Requirement already satisfied: numpy in ./anaconda3/lib/python3.6/site-packages (from numba>=0.34->umap-learn)

Running the example,

import umap
from sklearn.datasets import load_digits

digits = load_digits()

embedding = umap.UMAP().fit_transform(digits.data)

outputs:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-32-e5c7a5ee7150> in <module>()
      4 digits = load_digits()
      5 
----> 6 embedding = umap.UMAP().fit_transform(digits.data)

~/anaconda3/lib/python3.6/site-packages/umap/umap_.py in fit_transform(self, X, y)

~/anaconda3/lib/python3.6/site-packages/umap/umap_.py in fit(self, X, y)

~/anaconda3/lib/python3.6/site-packages/umap/umap_.py in simplicial_set_embedding(graph, n_components, initial_alpha, a, b, gamma, negative_sample_rate, n_epochs, init, random_state, verbose)

~/anaconda3/lib/python3.6/site-packages/umap/umap_.py in spectral_layout(graph, dim, random_state)

AttributeError: module 'scipy.sparse' has no attribute 'csgraph'

But I can import csgraph witout problems from scipy, from scipy.sparse import csgraph

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Reactions: 3
  • Comments: 26 (8 by maintainers)

Commits related to this issue

Most upvoted comments

Scipy 1.1.0 has release, so in ubuntu python 3.6.4 just pip install -U scipy scipy 1.1.0 installed, problem sloved!

You can maybe exclude scipy==1.0 in setup.py.

Thanks @wflynny and @gforsyth That looks like it is the source of the issue. I believe I added the relevant import in master, but hadn’t rolled out a pip release yet. I’ll try to get that done tonight and hopefully people will be seeing fewer issues.

I can confirm that I just ran into this using SciPy 1.0.0 and @wflynny has identified the fix for the compatibility regression. If the preference is for the smallest change, I think adding in a import scipy.sparse.csgraph will do the trick (as a stopgap until SciPy 1.0.1 is released)

Hello,

Yes. I was running on a Jupyter Notebook with Python 3.6.4 and Ubuntu 17.10.

from scipy.sparse.csgraph import connected_components is all I had to add to umap_.py to get it working.

I installed umap-learn on my other system without any problems. I accidentally installed umap, as I did the first time, and wondered if this was causing any problems? I removed it and reinstalled umap-learn to get everything working on the other system.

Is this specific to Jupyter notebooks? I am on Ubuntu 16.04, python 3.5.2.

import umap
from sklearn.datasets import load_digits
#from scipy.sparse.csgraph import connected_components

digits = load_digits()

embedding = umap.UMAP(n_neighbors=5,
                      min_dist=0.3,
                      metric='correlation').fit_transform(digits.data)

The code above works if I start python from the command line, but doesn’t work in a Jupyter notebook. If i uncomment the import it works in the notebook.

can’t actually reproduce it myself

@arnaudmiribel and @amirsani, What system are you are using? Operating system w/ version and Python version.

We might be able add to add them to the Travis CI test runs. Currently, it’s a little sparse running only on conda with 3.6 and 2.7.