🤍 전 강의 25% 할인 중 🤍

2024년 상반기를 돌아보고 하반기에도 함께 성장해요!
인프런이 준비한 25% 할인 받으러 가기 >>

  • 카테고리

    질문 & 답변
  • 세부 분야

    딥러닝 · 머신러닝

  • 해결 여부

    미해결

imblearn 관련

22.08.21 00:46 작성 조회수 1.61k

0

imblearn을 설치 후 실행 시 아래와 같은 오류가 발생합니다.
(영상에서는 imblearn Version이 0.9.0인데, 저는 0.7.0으로 설치가 되었네요) 구글링으로 해결이 되지 않아... 해결방법을 문의드립니다.
 

답변 5

·

답변을 작성해보세요.

0

다운그레이드 후 정상 동작합니다!! 빠른 회신과 정확한 답변에 감탄했습니다. 정말 감사합니다 👍🏻

0

imblearn과 scikit learn 1.1.2 가 잘 안맞는 것 같군요. 

1.1.2는 2022년 8월 출시 버전인데 최근에 사이킷런을 upgrade하신것 같군요. 

사이킷런을 설치하면 threadpoolctl 모듈도 같이 설치하는데 이게 뭔가 버전이 잘 안맞는 것 같습니다. 

pip로 설치하셨으면 pip uninstall scikit-learn으로 사이킷런을 삭제하신 후에 pip install scikit-learn==1.0.2 로 scikit learn을 downgrade 해보시지요

conda로 하셨으면 conda install scikit-learn=1.0.2 로 해보시지요. 

0

오류 전체 메세지 입니다!!





---------------------------------------------------------------------------
AttributeError Traceback (most recent call last) Input In [30], in <cell line: 4>() 1 from imblearn.over_sampling import SMOTE 3 smote = SMOTE(random_state=0) ----> 4 X_train_over, y_train_over = smote.fit_resample(X_train, y_train) 5 print('SMOTE 적용 전 학습용 피처/레이블 데이터 세트: ', X_train.shape, y_train.shape) 6 print('SMOTE 적용 후 학습용 피처/레이블 데이터 세트: ', X_train_over.shape, y_train_over.shape) File ~/opt/anaconda3/lib/python3.9/site-packages/imblearn/base.py:83, in SamplerMixin.fit_resample(self, X, y) 77 X, y, binarize_y = self._check_X_y(X, y) 79 self.sampling_strategy_ = check_sampling_strategy( 80 self.sampling_strategy, y, self._sampling_type 81 ) ---> 83 output = self._fit_resample(X, y) 85 y_ = ( 86 label_binarize(output[1], classes=np.unique(y)) if binarize_y else output[1] 87 ) 89 X_, y_ = arrays_transformer.transform(output[0], y_) File ~/opt/anaconda3/lib/python3.9/site-packages/imblearn/over_sampling/_smote/base.py:324, in SMOTE._fit_resample(self, X, y) 321 X_class = _safe_indexing(X, target_class_indices) 323 self.nn_k_.fit(X_class) --> 324 nns = self.nn_k_.kneighbors(X_class, return_distance=False)[:, 1:] 325 X_new, y_new = self._make_samples( 326 X_class, y.dtype, class_sample, X_class, nns, n_samples, 1.0 327 ) 328 X_resampled.append(X_new) File ~/opt/anaconda3/lib/python3.9/site-packages/sklearn/neighbors/_base.py:763, in KNeighborsMixin.kneighbors(self, X, n_neighbors, return_distance) 756 use_pairwise_distances_reductions = ( 757 self._fit_method == "brute" 758 and PairwiseDistancesArgKmin.is_usable_for( 759 X if X is not None else self._fit_X, self._fit_X, self.effective_metric_ 760 ) 761 ) 762 if use_pairwise_distances_reductions: --> 763 results = PairwiseDistancesArgKmin.compute( 764 X=X, 765 Y=self._fit_X, 766 k=n_neighbors, 767 metric=self.effective_metric_, 768 metric_kwargs=self.effective_metric_params_, 769 strategy="auto", 770 return_distance=return_distance, 771 ) 773 elif ( 774 self._fit_method == "brute" and self.metric == "precomputed" and issparse(X) 775 ): 776 results = _kneighbors_from_graph( 777 X, n_neighbors=n_neighbors, return_distance=return_distance 778 ) File sklearn/metrics/_pairwise_distances_reduction.pyx:698, in sklearn.metrics._pairwise_distances_reduction.PairwiseDistancesArgKmin.compute() File ~/opt/anaconda3/lib/python3.9/site-packages/sklearn/utils/fixes.py:151, in threadpool_limits(limits, user_api) 149 return controller.limit(limits=limits, user_api=user_api) 150 else: --> 151 return threadpoolctl.threadpool_limits(limits=limits, user_api=user_api) File ~/opt/anaconda3/lib/python3.9/site-packages/threadpoolctl.py:171, in threadpool_limits.__init__(self, limits, user_api) 167 def __init__(self, limits=None, user_api=None): 168 self._limits, self._user_api, self._prefixes = \ 169 self._check_params(limits, user_api) --> 171 self._original_info = self._set_threadpool_limits() File ~/opt/anaconda3/lib/python3.9/site-packages/threadpoolctl.py:268, in threadpool_limits._set_threadpool_limits(self) 265 if self._limits is None: 266 return None --> 268 modules = _ThreadpoolInfo(prefixes=self._prefixes, 269 user_api=self._user_api) 270 for module in modules: 271 # self._limits is a dict {key: num_threads} where key is either 272 # a prefix or a user_api. If a module matches both, the limit 273 # corresponding to the prefix is chosed. 274 if module.prefix in self._limits: File ~/opt/anaconda3/lib/python3.9/site-packages/threadpoolctl.py:340, in _ThreadpoolInfo.__init__(self, user_api, prefixes, modules) 337 self.user_api = [] if user_api is None else user_api 339 self.modules = [] --> 340 self._load_modules() 341 self._warn_if_incompatible_openmp() 342 else: File ~/opt/anaconda3/lib/python3.9/site-packages/threadpoolctl.py:371, in _ThreadpoolInfo._load_modules(self) 369 """Loop through loaded libraries and store supported ones""" 370 if sys.platform == "darwin": --> 371 self._find_modules_with_dyld() 372 elif sys.platform == "win32": 373 self._find_modules_with_enum_process_module_ex() File ~/opt/anaconda3/lib/python3.9/site-packages/threadpoolctl.py:428, in _ThreadpoolInfo._find_modules_with_dyld(self) 425 filepath = filepath.decode("utf-8") 427 # Store the module if it is supported and selected --> 428 self._make_module_from_path(filepath) File ~/opt/anaconda3/lib/python3.9/site-packages/threadpoolctl.py:515, in _ThreadpoolInfo._make_module_from_path(self, filepath) 513 if prefix in self.prefixes or user_api in self.user_api: 514 module_class = globals()[module_class] --> 515 module = module_class(filepath, prefix, user_api, internal_api) 516 self.modules.append(module) File ~/opt/anaconda3/lib/python3.9/site-packages/threadpoolctl.py:606, in _Module.__init__(self, filepath, prefix, user_api, internal_api) 604 self.internal_api = internal_api 605 self._dynlib = ctypes.CDLL(filepath, mode=_RTLD_NOLOAD) --> 606 self.version = self.get_version() 607 self.num_threads = self.get_num_threads() 608 self._get_extra_info() File ~/opt/anaconda3/lib/python3.9/site-packages/threadpoolctl.py:646, in _OpenBLASModule.get_version(self) 643 get_config = getattr(self._dynlib, "openblas_get_config", 644 lambda: None) 645 get_config.restype = ctypes.c_char_p --> 646 config = get_config().split() 647 if config[0] == b"OpenBLAS": 648 return config[1].decode("utf-8") AttributeError: 'NoneType' object has no attribute 'split'

0

Imblearn과 scikit-learn 모두 Version Update 하였으며,  Version은 아래와 같습니다. 아래와 같이 동일한 오류가 발생하고 있습니다. 

 

imbalanced-learn : 0.9.1

scikit-learn : 1.1.2

 

오류가 smote.fit_resample()에서 발생하나요? 

전체 오류 메시지를 복사해서 여기에 글로 올려 주시겠습니까?

0

안녕하십니까,  

아래와 같이 설치를 수행하고 버전을 확인해 보시기 바랍니다. 

pip install -U imbalanced-learn

 

감사합니다. 

채널톡 아이콘