AttributeError:' nonepy'对象没有属性' split' Smote

发布于 2025-01-30 05:40:33 字数 4812 浏览 4 评论 0 原文

我正在使用Smote重新采样一些数据并获得这样的错误:

attributeError:'nontype'对象没有属性“拆分”

我的代码:

sm = SMOTE(random_state = 42)
X_train_resampled, y_train_resampled = sm.fit_resample(X_train_final, y_train)

有人可以帮助我解决此问题吗?因为我的数据充分问题似乎没有任何问题

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-49-9465f7b6ac21> in <module>
      1 #resample data using SMOTE
      2 sm = SMOTE(random_state = 42)
----> 3 X_train_resampled, y_train_resampled = sm.fit_resample(X_train_final, y_train)

~\AppData\Roaming\Python\Python38\site-packages\imblearn\base.py in fit_resample(self, X, y)
     81         )
     82 
---> 83         output = self._fit_resample(X, y)
     84 
     85         y_ = (

~\AppData\Roaming\Python\Python38\site-packages\imblearn\over_sampling\_smote\base.py in _fit_resample(self, X, y)
    322 
    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

~\AppData\Roaming\Python\Python38\site-packages\sklearn\neighbors\_base.py in kneighbors(self, X, n_neighbors, return_distance)
    761         )
    762         if use_pairwise_distances_reductions:
--> 763             results = PairwiseDistancesArgKmin.compute(
    764                 X=X,
    765                 Y=self._fit_X,

sklearn\metrics\_pairwise_distances_reduction.pyx in sklearn.metrics._pairwise_distances_reduction.PairwiseDistancesArgKmin.compute()

~\AppData\Roaming\Python\Python38\site-packages\sklearn\utils\fixes.py 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)
    152 
    153 

C:\ProgramData\Anaconda3\lib\site-packages\threadpoolctl.py in __init__(self, limits, user_api)
    169             self._check_params(limits, user_api)
    170 
--> 171         self._original_info = self._set_threadpool_limits()
    172 
    173     def __enter__(self):

C:\ProgramData\Anaconda3\lib\site-packages\threadpoolctl.py in _set_threadpool_limits(self)
    266             return None
    267 
--> 268         modules = _ThreadpoolInfo(prefixes=self._prefixes,
    269                                   user_api=self._user_api)
    270         for module in modules:

C:\ProgramData\Anaconda3\lib\site-packages\threadpoolctl.py in __init__(self, user_api, prefixes, modules)
    338 
    339             self.modules = []
--> 340             self._load_modules()
    341             self._warn_if_incompatible_openmp()
    342         else:

C:\ProgramData\Anaconda3\lib\site-packages\threadpoolctl.py in _load_modules(self)
    371             self._find_modules_with_dyld()
    372         elif sys.platform == "win32":
--> 373             self._find_modules_with_enum_process_module_ex()
    374         else:
    375             self._find_modules_with_dl_iterate_phdr()

C:\ProgramData\Anaconda3\lib\site-packages\threadpoolctl.py in _find_modules_with_enum_process_module_ex(self)
    483 
    484                 # Store the module if it is supported and selected
--> 485                 self._make_module_from_path(filepath)
    486         finally:
    487             kernel_32.CloseHandle(h_process)

C:\ProgramData\Anaconda3\lib\site-packages\threadpoolctl.py in _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)
    517 

C:\ProgramData\Anaconda3\lib\site-packages\threadpoolctl.py in __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()

C:\ProgramData\Anaconda3\lib\site-packages\threadpoolctl.py in get_version(self)
    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'

我试图进一步研究自己拥有的数据,但似乎找不到任何问题。

I'm resampling some data using SMOTE and getting an error like this:

AttributeError: 'NoneType' object has no attribute 'split'

my code :

sm = SMOTE(random_state = 42)
X_train_resampled, y_train_resampled = sm.fit_resample(X_train_final, y_train)

can someone help me fixing this problem? because seems i dont have any problem with my data

full problem :

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-49-9465f7b6ac21> in <module>
      1 #resample data using SMOTE
      2 sm = SMOTE(random_state = 42)
----> 3 X_train_resampled, y_train_resampled = sm.fit_resample(X_train_final, y_train)

~\AppData\Roaming\Python\Python38\site-packages\imblearn\base.py in fit_resample(self, X, y)
     81         )
     82 
---> 83         output = self._fit_resample(X, y)
     84 
     85         y_ = (

~\AppData\Roaming\Python\Python38\site-packages\imblearn\over_sampling\_smote\base.py in _fit_resample(self, X, y)
    322 
    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

~\AppData\Roaming\Python\Python38\site-packages\sklearn\neighbors\_base.py in kneighbors(self, X, n_neighbors, return_distance)
    761         )
    762         if use_pairwise_distances_reductions:
--> 763             results = PairwiseDistancesArgKmin.compute(
    764                 X=X,
    765                 Y=self._fit_X,

sklearn\metrics\_pairwise_distances_reduction.pyx in sklearn.metrics._pairwise_distances_reduction.PairwiseDistancesArgKmin.compute()

~\AppData\Roaming\Python\Python38\site-packages\sklearn\utils\fixes.py 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)
    152 
    153 

C:\ProgramData\Anaconda3\lib\site-packages\threadpoolctl.py in __init__(self, limits, user_api)
    169             self._check_params(limits, user_api)
    170 
--> 171         self._original_info = self._set_threadpool_limits()
    172 
    173     def __enter__(self):

C:\ProgramData\Anaconda3\lib\site-packages\threadpoolctl.py in _set_threadpool_limits(self)
    266             return None
    267 
--> 268         modules = _ThreadpoolInfo(prefixes=self._prefixes,
    269                                   user_api=self._user_api)
    270         for module in modules:

C:\ProgramData\Anaconda3\lib\site-packages\threadpoolctl.py in __init__(self, user_api, prefixes, modules)
    338 
    339             self.modules = []
--> 340             self._load_modules()
    341             self._warn_if_incompatible_openmp()
    342         else:

C:\ProgramData\Anaconda3\lib\site-packages\threadpoolctl.py in _load_modules(self)
    371             self._find_modules_with_dyld()
    372         elif sys.platform == "win32":
--> 373             self._find_modules_with_enum_process_module_ex()
    374         else:
    375             self._find_modules_with_dl_iterate_phdr()

C:\ProgramData\Anaconda3\lib\site-packages\threadpoolctl.py in _find_modules_with_enum_process_module_ex(self)
    483 
    484                 # Store the module if it is supported and selected
--> 485                 self._make_module_from_path(filepath)
    486         finally:
    487             kernel_32.CloseHandle(h_process)

C:\ProgramData\Anaconda3\lib\site-packages\threadpoolctl.py in _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)
    517 

C:\ProgramData\Anaconda3\lib\site-packages\threadpoolctl.py in __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()

C:\ProgramData\Anaconda3\lib\site-packages\threadpoolctl.py in get_version(self)
    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'

I have tried to look further into the data I have but I can't seem to find any problems.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

葬シ愛 2025-02-06 05:40:33

我发现SMOTE在数据框中无法处理超过15列。更多的列会引起Smote的问题,并且“无类型”异常会引起。
您必须安装ThreadPoolCtl软件包才能解决该问题。

pip install -U threadpoolctl

I found out that SMOTE cannot handle more than 15 columns in your data frame. More columns cause issues in SMOTE and a "None Type" exception will raise.
You have to install threadpoolctl package to resolve the issue.

pip install -U threadpoolctl
何以心动 2025-02-06 05:40:33

我没有为上述问题提供解决方案(使用Smote时我也面临着这一点),而是解决问题的小建议。

您可以使用其他与smote相关的方法,例如ordendlinesmote等。
就我而言,使用边界线索解决了问题。

此外,我觉得边缘线略微好一些。因为Smote可能会遇到一些问题。
您可以参考以下网站以获取更多信息: -

我希望它能提供某种帮助。

I am not providing a solution to the above problem(which I also faced when using SMOTE), but a small suggestion to work around the problem.

You can use other methods related to SMOTE like BorderlineSMOTE etc.
In my case, using BorderlineSMOTE solved the problem.

Further, I felt that BorderlineSMOTE is slightly better. As SMOTE can have some problems.
You can refer to the following sites for more info:-

  1. Compare over-sampling samplers
  2. Oversampling with SMOTE and ADASYN

I hope it provides some kind of help.

烟若柳尘 2025-02-06 05:40:33

这些错误由于依赖性不一致而发生。运行这些命令以检查库的版本。接下来,转到分销商的官方网站,在这种情况下, https://scikit-learn.org/ 。然后检查您的软件包的版本是否匹配网站上提到的依赖项的版本。

import sklearn
print(sklearn.show_versions())

以上命令生成结果:

Python dependencies:
      sklearn: 1.2.1
          pip: 21.2.4
   setuptools: 58.0.4
        numpy: 1.22.4
        scipy: 1.7.1
       Cython: 0.29.24
       pandas: 1.3.4
   matplotlib: 3.4.3
       joblib: 1.2.0
threadpoolctl: 3.1.0

如果您要安装这些版本,则不会遇到任何问题。 numpy和threadpoolctl版本最重要。

These kinds of errors occur due to inconsistent dependencies. Run these commands to check the versions of your libraries. Next, go to the official site of the distributor, in this case, https://scikit-learn.org/. Then check whether your packages' versions match the versions of the dependencies mentioned on the site.

import sklearn
print(sklearn.show_versions())

The above commands generate the results:

Python dependencies:
      sklearn: 1.2.1
          pip: 21.2.4
   setuptools: 58.0.4
        numpy: 1.22.4
        scipy: 1.7.1
       Cython: 0.29.24
       pandas: 1.3.4
   matplotlib: 3.4.3
       joblib: 1.2.0
threadpoolctl: 3.1.0

If you will install these versions you will not face any issues. Numpy and threadpoolctl versions matters most.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文