每当我尝试在Jupyter notebook上运行以下代码行-从imblearn.under_sampling导入NearMiss进行欠采样(或过采样)不平衡数据时,我得到这个错误:
“”“
---------------------------------------------------------------------------
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)
“”“
发布于 2021-04-04 21:30:36
对于imblearn.under_sampling,您是否尝试过重新安装该软件包?:
pip install imbalanced-learn
conda:
conda install -c conda-forge imbalanced-learn
在jupyter笔记本中:
import sys
!{sys.executable} -m pip install <package_name>
如果你有scikitlearn>=0.24 (据我所知,现在有一个对imblearn的依赖,就像scikit-learn (>=0.23) https://imbalanced-learn.org/stable/install.html),你可能想试试:
try:
from sklearn.utils import safe_indexing
except ImportError:
from sklearn.utils import _safe_indexing
发布于 2021-05-26 21:17:32
编辑..\Anaconda3\Lib\site-packages\sklearn\utils\ init.py
复制定义_safe_indexing ...直到下一次定义。并将重命名的代码粘贴到def safe_indexing..
保持以前的_safe_indexing不变。
它解决了这个问题。
https://stackoverflow.com/questions/66941530
复制相似问题