ImportError: cannot import name 'safe_indexing' from 'sklearn.utils'
See original GitHub issueDescribe the bug
I’m trying to import KElbowVisualizer from yellowbrick.cluster, and it is returning the following error:
ImportError: cannot import name 'safe_indexing' from 'sklearn.utils'
To Reproduce
import pandas as pd
from sklearn.cluster import KMeans
from yellowbrick.cluster import KElbowVisualizer
Traceback
mportError: cannot import name 'safe_indexing' from 'sklearn.utils' (~/.venv/lib/python3.8/site-packages/sklearn/utils/__init__.py)
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-3-eb5694100c70> in <module>
1 import pandas as pd
----> 2 from yellowbrick.cluster import KElbowVisualizer
~/.venv/lib/python3.8/site-packages/yellowbrick/__init__.py in <module>
37 from .anscombe import anscombe
38 from .datasaurus import datasaurus
---> 39 from .classifier import ROCAUC, ClassBalance, ClassificationScoreVisualizer
40
41 # from .classifier import crplot, rocplot
~/.venv/lib/python3.8/site-packages/yellowbrick/classifier/__init__.py in <module>
28 from .confusion_matrix import ConfusionMatrix, confusion_matrix
29 from .rocauc import ROCAUC, roc_auc
---> 30 from .threshold import DiscriminationThreshold, discrimination_threshold
31 from .prcurve import PrecisionRecallCurve, PRCurve, precision_recall_curve
32
~/Repositories/player-similarity-clusters/.venv/lib/python3.8/site-packages/yellowbrick/classifier/threshold.py in <module>
28 from sklearn.model_selection import ShuffleSplit
29 from sklearn.metrics import precision_recall_curve
---> 30 from sklearn.utils import indexable, safe_indexing
31 from sklearn.utils.multiclass import type_of_target
32
ImportError: cannot import name 'safe_indexing' from 'sklearn.utils' (~/.venv/lib/python3.8/site-packages/sklearn/utils/__init__.py)
Desktop (please complete the following information):
- OS: Ubuntu 20.04
- Python Version: 3.8.5
- Yellowbrick Version: 1.2
Additional context
- skleaarn Version: 0.24.0
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:20 (11 by maintainers)
Top Results From Across the Web
cannot import name 'safe_indexing' from 'sklearn.utils' - ...
In python3.7 with yellowbrick v1.2 and scikit-learn v0.23.2 I don't get the error but when I bump scikit-learn to v0.24.0 I get the...
Read more >more_vert
The code above is work well. However, after run the code below, it shows 'ImportError: cannot import name '_raise_dep_warning_if_not_pytest' from 'sklearn.utils ...
Read more >Import error rand_score
When I try to install any new packages that are stable I get error ... 1 from sklearn.metrics import rand_score ImportError: cannot import...
Read more >Source code for yellowbrick.classifier.threshold
... ImportError: from sklearn.utils import _safe_indexing from yellowbrick.base import ModelVisualizer from yellowbrick.style.colors import ...
Read more >PYTHON : ImportError in importing from sklearn - YouTube
PYTHON : ImportError in importing from sklearn : cannot import name check_build [ Gift : Animated Search Engine ...
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 FreeTop 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
Top GitHub Comments
Hi @Paulj1989 and thanks for letting us know!
It looks like scikit-learn has again changed their public/private API, so
utils.safe_indexing
is now calledutils._safe_indexing
. In order for the utility to work in Yellowbrick, we will have to change our usage ofsafe_indexing
to support users with versions of scikit-learn >= 0.24 without deprecating support for users with versions of scikit-learn < 0.24. We’ll need to change our import statement for safe_indexing at the top ofthreshold.py
to something like the below and test that it works properly:If you would like to open a PR to work on this, let us know! We are a small team of unpaid volunteers who work on Yellowbrick in our spare time, so we’d welcome your help. In the meantime, you can avoid the error by downgrading your version of scikit-learn to <0.24
Thanks again for checking out Yellowbrick and giving us a heads up about the new sklearn API changes!
@rrsquez I think you may be misunderstanding the purpose of our GitHub issues - this is the place where users of Yellowbrick report bugs to the coders and maintainers who work on Yellowbrick. Note that the maintainers here are professional software engineers, data scientists, and educators who develop Yellowbrick in their free time as an open-source project and not for pay. Although they are happy to answer your questions, they cannot read your mind or see your computer and so must provide debugging suggestions for you to work through. In your case, your problem had nothing to do with Yellowbrick, but with your own Python environment.
Your comment is disrespectful and inappropriate and contributed nothing constructive to this discussion. I would ask that you please apologize to @ShahbazT, @rebeccabilbro, and @Paulj1989 if you’d like to continue to be a part of our community. In the future, please consider your words more carefully and speak with respect as described by our code of conduct. Failure to abide by these requests will result in our blocking you from this repository.