AttributeError: module 'scipy' has no attribute 'sparse' in sklearn/utils/fixes.py
See original GitHub issueDescription
I have updated sklearn, scipy (previously all worked fine). As a result, the error started to occur in sklearn\utils\fixes.py:
AttributeError: module 'scipy' has no attribute 'sparse'
I have tried to execute the same import command from fixes.py and it failed with error:
import scipy.sparse as sp
Following command is working:
from scipy import sparse
Steps/Code to Reproduce
from sklearn import datasets
iris = datasets.load_iris()
Expected Results
No error is thrown
Actual Results
File "....projects/Test.py", line 8, in <module>
from sklearn import datasets
File "C:\ProgramData\Anaconda3\lib\site-packages\sklearn\__init__.py", line 64, in <module>
from .base import clone
File "C:\ProgramData\Anaconda3\lib\site-packages\sklearn\base.py", line 14, in <module>
from .utils.fixes import signature
File "C:\ProgramData\Anaconda3\lib\site-packages\sklearn\utils\__init__.py", line 16, in <module>
from .fixes import _Sequence as Sequence
File "C:\ProgramData\Anaconda3\lib\site-packages\sklearn\utils\fixes.py", line 20, in <module>
import scipy.sparse as sp
AttributeError: module 'scipy' has no attribute 'sparse'
Versions
python: 3.6.8 scikit-learn 0.20.3 numpy: 1.15.4 scipy: 1.2.1 platform: Windows-8.1-6.3.9600-SP0
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (3 by maintainers)
Top Results From Across the Web
Why does this AttributeError in python occur? - Stack Overflow
This happens because the scipy module doesn't have any attribute named sparse . That attribute only gets defined when you import ...
Read more >module 'scipy' has no attribute 'sparse'
I wrote a function to create a random sparse Matrix. but when I run the code in Pycham, I get following error: C...
Read more >AttributeError: 'numpy.ndarray' object has no attribute 'fit' [closed]
I am creating a pipeline of custom transformers and get this error: AttributeError: 'numpy.ndarray' object has no attribute 'fit'. Below is the ...
Read more >Implementing privacy preservation through Python - Kaggle
A short intro to privacy preservation¶. With the ever growing number of datasets being published, there is an increased risk of seeing personal...
Read more >Date-A-Scientist - Scikit-Learn Import error
C:/Users/Lucas/anaconda3/python.exe "d:/Projetos/Code/Date a ... AttributeError: 'str' object has no attribute 'str'. x.find():.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@TatianaParshina what versions are you running? I have the following:
numpy-1.18.1 scikit-learn-0.22.1 scipy-1.4.1and am receiving the same errors after reinstall.
Yes, I saw earlier posts and checked for that. I just needed to import sparse in addition to scipy.