2

我重新安装了最新的 scikit-learn 和不平衡学习。我还检查了所有其他库以确保它与 Imbalanced-learn 兼容。我只想运行一个简单的 RandomOverSample(),但我收到以下导入错误消息,任何建议都会有所帮助。谢谢!

import imblearn
from imblearn.over_sampling import RandomOverSampler

ros = RandomOverSampler()
X_ros, y_ros = ros.fit_sample(x, y)

错误信息:

    ---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-122-0bf7409a8688> in <module>
----> 1 import imblearn
      2 from imblearn.over_sampling import RandomOverSampler
      3 
      4 ros = RandomOverSampler()
      5 X_ros, y_ros = ros.fit_sample(x, y)

~/.local/lib/python3.5/site-packages/imblearn/__init__.py in <module>
     32     Module which allowing to create pipeline with scikit-learn estimators.
     33 """
---> 34 from . import combine
     35 from . import ensemble
     36 from . import exceptions

~/.local/lib/python3.5/site-packages/imblearn/combine/__init__.py in <module>
      3 """
      4 
----> 5 from ._smote_enn import SMOTEENN
      6 from ._smote_tomek import SMOTETomek
      7 

~/.local/lib/python3.5/site-packages/imblearn/combine/_smote_enn.py in <module>
      8 from sklearn.utils import check_X_y
      9 
---> 10 from ..base import BaseSampler
     11 from ..over_sampling import SMOTE
     12 from ..over_sampling.base import BaseOverSampler

~/.local/lib/python3.5/site-packages/imblearn/base.py in <module>
     14 from sklearn.utils.multiclass import check_classification_targets
     15 
---> 16 from .utils import check_sampling_strategy, check_target_type
     17 from .utils._validation import ArraysTransformer
     18 

~/.local/lib/python3.5/site-packages/imblearn/utils/__init__.py in <module>
      5 from ._docstring import Substitution
      6 
----> 7 from ._validation import check_neighbors_object
      8 from ._validation import check_target_type
      9 from ._validation import check_sampling_strategy

~/.local/lib/python3.5/site-packages/imblearn/utils/_validation.py in <module>
     11 
     12 from sklearn.base import clone
---> 13 from sklearn.neighbors._base import KNeighborsMixin
     14 from sklearn.neighbors import NearestNeighbors
     15 from sklearn.utils import column_or_1d

~/.local/lib/python3.5/site-packages/sklearn/neighbors/_base.py in <module>
     21 from ._ball_tree import BallTree
     22 from ._kd_tree import KDTree
---> 23 from ..base import BaseEstimator, MultiOutputMixin
     24 from ..metrics import pairwise_distances_chunked
     25 from ..metrics.pairwise import PAIRWISE_DISTANCE_FUNCTIONS

ImportError: cannot import name 'MultiOutputMixin'
4

2 回答 2

4

尝试打开一个新的 python 控制台或重新启动 jupyter notebook。这对我有用。看起来 imblearn 库需要重新启动才能工作。这个问题也在这里讨论。 ImportError:无法从“sklearn.base”导入名称“MultiOutputMixin”

于 2020-07-04T13:03:57.543 回答
0

经过一番挖掘,我必须重新安装到最新的 scikit 学习包。

于 2020-02-19T05:07:12.343 回答