![](/img/trans.png)
[英]YellowBrick ImportError: cannot import name 'safe_indexing' from 'sklearn.utils'
[英]ImportError: cannot import name 'safe_indexing' from 'sklearn.utils'
每当我尝试运行以下代码行时:
from imblearn.under_sampling import NearMiss
对于 Jupyter 笔记本上的欠采样(或过采样)不平衡数据,我收到此错误:
ImportError Traceback (most recent call last)
<ipython-input-21-c701341dce49> in <module>
----> 1 from imblearn.under_sampling import NearMiss
~\anaconda3\lib\site-packages\imblearn\under_sampling\__init__.py in <module>
4 """
5
----> 6 from ._prototype_generation import ClusterCentroids
7
8 from ._prototype_selection import RandomUnderSampler
~\anaconda3\lib\site-packages\imblearn\under_sampling\_prototype_generation\__init__.py in <module>
4 """
5
----> 6 from ._cluster_centroids import ClusterCentroids
7
8 __all__ = ['ClusterCentroids']
~\anaconda3\lib\site-packages\imblearn\under_sampling\_prototype_generation\_cluster_centroids.py in <module>
15 from sklearn.cluster import KMeans
16 from sklearn.neighbors import NearestNeighbors
---> 17 from sklearn.utils import safe_indexing
18
19 from ..base import BaseUnderSampler
ImportError: cannot import name 'safe_indexing' from 'sklearn.utils' (C:\Users\anaconda3\lib\site-packages\sklearn\utils\__init__.py)
对于 imblearn.under_sampling,您是否尝试重新安装 package?:
pip install imbalanced-learn
康达:
conda install -c conda-forge imbalanced-learn
在 jupyter 笔记本中:
import sys
!{sys.executable} -m pip install <package_name>
If you have scikitlearn>=0.24 (as far as i see there is a dependency for imblearn now,as scikit-learn (>=0.23) https://imbalanced-learn.org/stable/install.html ) you may want to try:
try:
from sklearn.utils import safe_indexing
except ImportError:
from sklearn.utils import _safe_indexing
编辑..\Anaconda3\Lib\site-packages\sklearn\utils\ __init__.py
。
复制def _safe_indexing...
直到下一个def
并将代码重命名为def safe_indexing...
。
保持以前_safe_indexing
。
它以这种方式解决了这个问题。
在~\Anaconda3\Lib\site-packages\yellowbrick\classifier\threshold.py
模块中替换:
from sklearn.utils import indexable, safe_indexing
和
from sklearn.utils import indexable, _safe_indexing
之后,重新启动 kernel。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.