我正在尝试在 mac 中运行下面的代码。
## Hyperparameter optimization using RandomizedSearchCV
from sklearn.model_selection import RandomizedSearchCV, GridSearchCV
from xgboost import XGBClassifier
它给了我以下错误。 请帮助我,我已经尝试解决这个问题两天多了。但没有运气。
弹出的错误如下所示,
---------------------------------------------------------------------------
XGBoostError Traceback (most recent call last)
<ipython-input-141-84c898b0388e> in <module>
1 ## Hyperparameter optimization using RandomizedSearchCV
2 from sklearn.model_selection import RandomizedSearchCV, GridSearchCV
----> 3 from xgboost import XGBClassifier
~/opt/anaconda3/lib/python3.8/site-packages/xgboost/__init__.py in <module>
7 import os
8
----> 9 from .core import DMatrix, DeviceQuantileDMatrix, Booster
10 from .training import train, cv
11 from . import rabit # noqa
~/opt/anaconda3/lib/python3.8/site-packages/xgboost/core.py in <module>
171
172 # load the XGBoost library globally
--> 173 _LIB = _load_lib()
174
175
~/opt/anaconda3/lib/python3.8/site-packages/xgboost/core.py in _load_lib()
154 if not lib_success:
155 libname = os.path.basename(lib_paths[0])
--> 156 raise XGBoostError(
157 'XGBoost Library ({}) could not be loaded.\n'.format(libname) +
158 'Likely causes:\n' +
XGBoostError: XGBoost Library (libxgboost.dylib) could not be loaded.
Likely causes:
* OpenMP runtime is not installed (vcomp140.dll or libgomp-1.dll for Windows, libomp.dylib for Mac OSX, libgomp.so for Linux and other UNIX-like OSes). Mac OSX users: Run `brew install libomp` to install OpenMP runtime.
* You are running 32-bit Python on a 64-bit OS
Error message(s): ['dlopen(/Users/danishali/opt/anaconda3/lib/python3.8/site-packages/xgboost/lib/libxgboost.dylib, 6): Library not loaded: /usr/local/opt/libomp/lib/libomp.dylib\n Referenced from: /Users/danishali/opt/anaconda3/lib/python3.8/site-packages/xgboost/lib/libxgboost.dylib\n Reason: image not found']
我遇到了同样的问题,但通过在终端上运行以下命令解决了它
brew install libomp
使用并行计算需要安装OpenMP https://carleton.ca/rcs/rcdc/introduction-to-openmp/ (就像其他评论所说的那样)