XGBoost 是一个用于开发非常快速和准确的梯度提升模型的库。
它是 Kaggle 数据科学竞赛中许多获胜解决方案的核心库。
在本教程中,您将了解如何在 macOS 上为 Python 安装 XGBoost 库。
通过我的新书《XGBoost With Python》启动您的项目,其中包括所有示例的分步教程和 Python 源代码文件。
让我们开始吧。

如何在 macOS 上为 Python 安装 XGBoost
照片由 auntjojo 提供,部分权利保留。
教程概述
本教程分为3个部分;它们是
- 安装 MacPorts
- 构建 XGBoost
- 安装 XGBoost
注意:我多年来一直在各种 macOS 版本上使用此过程,并且它没有改变。本教程是在 macOS High Sierra (10.13.1) 上编写和测试的。
1. 安装 MacPorts
您需要安装 GCC 和 Python 环境才能构建和安装 Python 版 XGBoost。
我推荐 GCC 7 和 Python 3.6,并建议使用 MacPorts 安装这些先决条件。
- 1. 有关分步安装 MacPorts 和 Python 环境的帮助,请参阅本教程
>> 如何在 Mac OS X 上为机器学习和深度学习安装 Python 3 环境
- 2. 安装 MacPorts 和可用的 Python 环境后,您可以如下安装并选择 GCC 7:
1 2 |
sudo port install gcc7 sudo port select --set gcc mp-gcc7 |
- 3. 如下确认您的 GCC 安装成功:
1 |
gcc -v |
您应该会看到 GCC 的版本打印出来;例如:
1 2 |
.. gcc version 7.2.0 (MacPorts gcc7 7.2.0_0) |
您看到了什么版本?
在下面的评论中告诉我。
2. 构建 XGBoost
下一步是下载并编译适用于您系统的 XGBoost。
- 1. 首先,从 GitHub 检出代码仓库
1 |
git clone --recursive https://github.com/dmlc/xgboost |
- 2. 进入 xgboost 目录。
1 |
cd xgboost/ |
- 3. 将我们打算用于编译 XGBoost 的配置文件复制到位。
1 |
cp make/config.mk ./config.mk |
- 4. 编译 XGBoost;这需要您指定系统上的核心数(例如 8,根据需要更改)。
1 |
make -j8 |
构建过程可能需要一分钟,并且不应产生任何错误消息,尽管您可能会看到一些可以安全忽略的警告。
例如,编译的最后一段可能如下所示:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
... a - build/learner.o a - build/logging.o a - build/c_api/c_api.o a - build/c_api/c_api_error.o a - build/common/common.o a - build/common/hist_util.o a - build/data/data.o a - build/data/simple_csr_source.o a - build/data/simple_dmatrix.o a - build/data/sparse_page_dmatrix.o a - build/data/sparse_page_raw_format.o a - build/data/sparse_page_source.o a - build/data/sparse_page_writer.o a - build/gbm/gblinear.o a - build/gbm/gbm.o a - build/gbm/gbtree.o a - build/metric/elementwise_metric.o a - build/metric/metric.o a - build/metric/multiclass_metric.o a - build/metric/rank_metric.o a - build/objective/multiclass_obj.o a - build/objective/objective.o a - build/objective/rank_obj.o a - build/objective/regression_obj.o a - build/predictor/cpu_predictor.o a - build/predictor/predictor.o a - build/tree/tree_model.o a - build/tree/tree_updater.o a - build/tree/updater_colmaker.o a - build/tree/updater_fast_hist.o a - build/tree/updater_histmaker.o a - build/tree/updater_prune.o a - build/tree/updater_refresh.o a - build/tree/updater_skmaker.o a - build/tree/updater_sync.o c++ -std=c++11 -Wall -Wno-unknown-pragmas -Iinclude -Idmlc-core/include -Irabit/include -I/include -O3 -funroll-loops -msse2 -fPIC -fopenmp -o xgboost build/cli_main.o build/learner.o build/logging.o build/c_api/c_api.o build/c_api/c_api_error.o build/common/common.o build/common/hist_util.o build/data/data.o build/data/simple_csr_source.o build/data/simple_dmatrix.o build/data/sparse_page_dmatrix.o build/data/sparse_page_raw_format.o build/data/sparse_page_source.o build/data/sparse_page_writer.o build/gbm/gblinear.o build/gbm/gbm.o build/gbm/gbtree.o build/metric/elementwise_metric.o build/metric/metric.o build/metric/multiclass_metric.o build/metric/rank_metric.o build/objective/multiclass_obj.o build/objective/objective.o build/objective/rank_obj.o build/objective/regression_obj.o build/predictor/cpu_predictor.o build/predictor/predictor.o build/tree/tree_model.o build/tree/tree_updater.o build/tree/updater_colmaker.o build/tree/updater_fast_hist.o build/tree/updater_histmaker.o build/tree/updater_prune.o build/tree/updater_refresh.o build/tree/updater_skmaker.o build/tree/updater_sync.o dmlc-core/libdmlc.a rabit/lib/librabit.a -pthread -lm -fopenmp |
这个步骤对您有效吗?
在下面的评论中告诉我。
3. 安装 XGBoost
您现在可以安装 XGBoost 到您的系统了。
- 1. 将目录更改到 xgboost 项目的 Python 包中。
1 |
cd python-package |
- 2. 安装 Python XGBoost 包。
1 |
sudo python setup.py install |
安装速度非常快。
例如,安装完成后,您可能会看到类似以下的输出:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
... Installed /opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/xgboost-0.6-py3.6.egg Processing dependencies for xgboost==0.6 Searching for scipy==1.0.0 Best match: scipy 1.0.0 Adding scipy 1.0.0 to easy-install.pth file Using /opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages Searching for numpy==1.13.3 Best match: numpy 1.13.3 Adding numpy 1.13.3 to easy-install.pth file Using /opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages Finished processing dependencies for xgboost==0.6 |
- 3. 通过打印 xgboost 版本来确认安装成功,这需要加载该库。
将以下代码保存到一个名为 version.py 的文件中。
1 2 |
import xgboost print("xgboost", xgboost.__version__) |
从命令行运行脚本
1 |
python version.py |
您应该会在屏幕上看到 XGBoost 版本
1 |
xgboost 0.6 |
您做得怎么样?
请在下方评论区发布你的结果。
进一步阅读
如果您想深入了解,本节提供了更多关于该主题的资源。
总结
在本教程中,您了解了如何在 macOS 上分步安装 XGBoost for Python。
你有什么问题吗?
在下面的评论中提出你的问题,我会尽力回答。
能发一个 Windows 版本的吗?
抱歉,我不知道 Windows 操作系统。
对于 Windows 安装,
https://ampersandacademy.com/tutorials/python-data-science/install-xgboost-on-windows-10-for-python-programming
感谢分享。
或者可以直接在 Docker 中使用:https://github.com/petronetto/machine-learning-alpine
谢谢。
这就是我的选择。
之后
$ gcc -v
我没有得到 gcc 版本,而是
Configured with: –prefix=/Library/Developer/CommandLineTools/usr –with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 9.0.0 (clang-900.0.39.2)
Target: x86_64-apple-darwin17.3.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
奇怪…
我还没有进一步尝试(仍然)
看起来您仍然在使用 apple 编译器。
您可能需要告诉 macports 您想使用新安装的编译器。
我遇到了同样的问题。但我通过使用命令 “hash -r” 来让终端识别更改,从而解决了它。根据这篇文章 https://stackoverflow.com/questions/8361002/how-to-use-the-gcc-installed-in-macports,打开一个新的终端窗口也可以。在使用 “hash -r” 后,“gcc -v” 显示的结果与本教程中的结果相同。
不错。
嗨 Jason
一切都很顺利,直到
make -j8
我收到了 fatal error,然后是 – 一些错误
/opt/local/include/gcc7/c++/cwchar:44:10: fatal error: wchar.h: No such file or directory
#include
.....
你有什么想法吗?
哦,天哪。抱歉,我没有好主意。
也许可以发到 stack overflow 或 xgboost 的 issue tracker
https://github.com/dmlc/xgboost/issues
或者尝试检出 v0.6 版本,看看在最近的 0.7 版本中是否有什么变化?
同样的错误
大家好,
我也有同样的错误。您是否已找出如何解决此问题?提前感谢!
也许可以尝试通过 pip 安装
嗨,Jason,
我只是使用了,
conda install -c conda-forge xgboost
所以我没有遵循步骤 1、2 和 3。但是,这取决于个人喜好。
谢谢
非常棒的提示,谢谢!
是的,这奏效了。
我顶这个!对我来说也奏效了。省了很多步骤!
谢谢。
顶!对我来说奏效了,谢谢 cgironda!
很高兴听到这个消息。
很棒的提示!谢谢
非常感谢!
Jason,
为什么您认为 Python 在机器学习方面比 R 或 Matlab 更好?
它们都很棒,但更多人希望在工作场所中使用,并且要求开发人员使用它。
https://machinelearning.org.cn/python-growing-platform-applied-machine-learning/
非常感谢!非常出色地奏效了。
不客气。
太棒了!我之前曾尝试使用 homebrew 安装 gcc,然后编辑 config.mk 文件,正如几乎所有其他教程都告诉您的那样,但一直收到错误。这是第一个对我奏效的方法(在 mac OS Sierra 10.12.6 上);非常感谢!
很高兴听到这个,Matt,干得好!
cgironda,您是明星!您可以花一天时间尝试回答有关
unsupported option '-fopenmp'
的所有问题,而您甚至无法接近所有问题。您在我折腾了大约 4 小时后拯救了我。谢谢!嗨,Jason,
我遵循了您的说明,直到第 2 步构建 XG boost,这是我在终端上看到的回复:
a – build/metric/metric.o
a – build/metric/multiclass_metric.o
a – build/metric/rank_metric.o
a – build/objective/multiclass_obj.o
a – build/objective/objective.o
a – build/objective/rank_obj.o
a – build/objective/regression_obj.o
a – build/predictor/cpu_predictor.o
a – build/predictor/predictor.o
a – build/tree/tree_model.o
a – build/tree/tree_updater.o
a – build/tree/updater_colmaker.o
a – build/tree/updater_fast_hist.o
a – build/tree/updater_histmaker.o
a – build/tree/updater_prune.o
a – build/tree/updater_refresh.o
a – build/tree/updater_skmaker.o
a – build/tree/updater_sync.o
ld: can’t open output file for writing: xgboost, errno=21 for architecture x86_64
collect2: error: ld returned 1 exit status
make: *** [xgboost] Error 1
make: *** Waiting for unfinished jobs….
Alvics-MacBook-Pro-2:xgboost alviceugenejosol$ a – b
哎呀。我没见过这个。
也许尝试 make clean,然后再次构建?
也许可以将错误发布到 xgboost 用户组?
嗨,Jason,
效果很好。感谢您提供详细的说明。
-A
太好了,我很高兴听到这个!
第 2 步不起作用……
Pauls-MacBook-Pro:xgboost pmw$ make -j8
Makefile:31: MAKE [/Library/Developer/CommandLineTools/usr/bin/make] – checked OK
c++ -DDMLC_LOG_CUSTOMIZE=1 -std=c++11 -Wall -Wno-unknown-pragmas -Iinclude -Idmlc-core/include -Irabit/include -I/include -O3 -funroll-loops -msse2 -fPIC -fopenmp -MM -MT build/c_api/c_api.o src/c_api/c_api.cc >build/c_api/c_api.d
c++ -DDMLC_LOG_CUSTOMIZE=1 -std=c++11 -Wall -Wno-unknown-pragmas -Iinclude -Idmlc-core/include -Irabit/include -I/include -O3 -funroll-loops -msse2 -fPIC -fopenmp -MM -MT build/logging.o src/logging.cc >build/logging.d
c++ -DDMLC_LOG_CUSTOMIZE=1 -std=c++11 -Wall -Wno-unknown-pragmas -Iinclude -Idmlc-core/include -Irabit/include -I/include -O3 -funroll-loops -msse2 -fPIC -fopenmp -MM -MT build/learner.o src/learner.cc >build/learner.d
c++ -DDMLC_LOG_CUSTOMIZE=1 -std=c++11 -Wall -Wno-unknown-pragmas -Iinclude -Idmlc-core/include -Irabit/include -I/include -O3 -funroll-loops -msse2 -fPIC -fopenmp -MM -MT build/c_api/c_api_error.o src/c_api/c_api_error.cc >build/c_api/c_api_error.d
c++ -DDMLC_LOG_CUSTOMIZE=1 -std=c++11 -Wall -Wno-unknown-pragmas -Iinclude -Idmlc-core/include -Irabit/include -I/include -O3 -funroll-loops -msse2 -fPIC -fopenmp -MM -MT build/common/common.o src/common/common.cc >build/common/common.d
c++ -DDMLC_LOG_CUSTOMIZE=1 -std=c++11 -Wall -Wno-unknown-pragmas -Iinclude -Idmlc-core/include -Irabit/include -I/include -O3 -funroll-loops -msse2 -fPIC -fopenmp -MM -MT build/common/hist_util.o src/common/hist_util.cc >build/common/hist_util.d
c++ -DDMLC_LOG_CUSTOMIZE=1 -std=c++11 -Wall -Wno-unknown-pragmas -Iinclude -Idmlc-core/include -Irabit/include -I/include -O3 -funroll-loops -msse2 -fPIC -fopenmp -MM -MT build/common/host_device_vector.o src/common/host_device_vector.cc >build/common/host_device_vector.d
c++ -DDMLC_LOG_CUSTOMIZE=1 -std=c++11 -Wall -Wno-unknown-pragmas -Iinclude -Idmlc-core/include -Irabit/include -I/include -O3 -funroll-loops -msse2 -fPIC -fopenmp -MM -MT build/data/data.o src/data/data.cc >build/data/data.d
clang: clangclang: : error: errorerrorunsupported option ‘-fopenmp’: : unsupported option ‘-fopenmp’unsupported option ‘-fopenmp’
clang: clang: error: unsupported option ‘-fopenmp’error
unsupported option ‘-fopenmp’
clang: error: unsupported option ‘-fopenmp’
clang: error: unsupported option ‘-fopenmp’
clang: error: unsupported option ‘-fopenmp’
make: *** [build/common/common.o] Error 1
make: *** Waiting for unfinished jobs….
make: *** [build/c_api/c_api_error.o] Error 1
make: *** [build/learner.o] Error 1
make: *** [build/logging.o] Error 1
make: *** [build/c_api/c_api.o] Error 1
make: *** [build/common/host_device_vector.o] Error 1
make: *** [build/common/hist_util.o] Error 1
make: *** [build/data/data.o] Error 1
也许尝试在您的工作站上使用 pip 安装?
例如
安装 MacPorts 后,我尝试 port install gcc,但收到错误,提示不存在名为 gcc7 的端口。尝试了几个变体。最后不得不执行 port install self update,然后其余的就顺利完成了。所以也许在安装 MacPorts 部分将 self update 添加为第一步。其他所有步骤都运行良好。感谢这篇文章和您所有的其他文章。
谢谢 Chris 的提示!
当我运行该步骤时
make -j4
我得到了一个错误
clang: error: unsupported option ‘-fopenmp’
clang: error: unsupported option ‘-fopenmp’
clang: clang: error: unsupported option ‘-fopenmp’error: unsupported option ‘-fopenmp’
make: *** [build/c_api/c_api_error.o] Error 1
make: *** Waiting for unfinished jobs….
make: *** [build/c_api/c_api.o] Error 1
make: *** [build/learner.o] Error 1
make: *** [build/logging.o] Error 1
有什么方法可以解决这个问题吗?
也许将编译器从 clang 改为 gcc?
嗨,Jason,
感谢您的辛勤工作!
在最后一步,我收到了上述错误。有什么修复建议吗?
apple@Apple-MacBook-Pro python-package % sudo python setup.py install
回溯(最近一次调用)
File “setup.py”, line 277, in
encoding=’utf-8′).read(),
TypeError: ‘encoding’ is an invalid keyword argument for this function
也许确保您使用的是 Python 3.6 或更高版本?
非常感谢 Jason。
在您评论之后,我明白了问题所在。
sudo python3 setup.py install 解决了这个问题。
祝好
干得好!
嗨,Jason,
感谢您的辛勤工作!
在最后一步,我收到了上述错误。有什么修复建议吗?
INFO:XGBoost build_ext:Building from source. /Users/smehta27/Desktop/Dental/xgboost/lib/libxgboost.dylib
error: [Errno 2] No such file or directory: ‘cmake’: ‘cmake’
看起来您需要安装 make,可能通过 macports 或 brew。
嗨,Jason,
一如既往的出色教程!
我使用的是 Mac OS Catalina,在安装 MacPorts 时遇到了一些问题,但这个链接很有帮助。
https://trac.macports.org/wiki/CatalinaProblems
谢谢你
干得好!
Jason,您好,感谢分享。
我从步骤2和步骤3开始操作。
对于步骤2,我没有找到与您类似的显示。相反,它变成了
Makefile:23: MAKE [/Library/Developer/CommandLineTools/usr/bin/make] – checked OK
c++ -c -DDMLC_LOG_CUSTOMIZE=1 -std=c++11 -Wall -Wno-unknown-pragmas -Iinclude -Idmlc-core/include -Irabit/include -I/include -O3 -funroll-loops amalgamation/xgboost-all0.cc -o amalgamation/xgboost-all0.o
在包含的文件 amalgamation/xgboost-all0.cc:76 中
amalgamation/../src/common/io.cc:102:8: 警告:未使用的变量 ‘ReadErr’
[-Wunused-variable]
auto ReadErr = [&fname]() {
^
在包含的文件 amalgamation/xgboost-all0.cc:13 中
在包含的文件 amalgamation/../src/metric/metric.cc:6 中
在包含的文件 dmlc-core/include/dmlc/./registry.h:9 中
在包含的文件 /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/map:479 中
在包含的文件 /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/__tree:15 中
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/memory:2338:5: 警告
delete 用于非 final 的 ‘xgboost::tree::QuantileHistMaker::Builder’
它具有虚函数但没有虚析构函数
[-Wdelete-non-abstract-non-virtual-dtor]
delete __ptr;
^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/memory:2651:7: 注意
在实例化成员函数
‘std::__1::default_delete::operator()’
此处需要
__ptr_.second()(__tmp);
^
amalgamation/../src/tree/updater_quantile_hist.cc:74:14: 注意:在实例化
成员函数
‘std::__1::unique_ptr<xgboost::tree::QuantileHistMaker::Builder,
std::__1::default_delete
>::reset’ 此处需要
builder_.reset(new Builder(
^
在包含的文件 amalgamation/xgboost-all0.cc:35 中
在包含的文件 amalgamation/../src/data/data.cc:24 中
在包含的文件 amalgamation/../src/data/./sparse_page_dmatrix.h:17 中
在包含的文件 amalgamation/../src/data/ellpack_page_source.h:13 中
amalgamation/../src/metric/../common/hist_util.h:695:10: 警告:私有字段
‘nthread_’ 未被使用 [-Wunused-private-field]
size_t nthread_ { 0 };
^
生成了 3 个警告。
然后,在执行步骤3时:出现错误信息
INFO:XGBoost build_ext:正在从源代码构建。 /Users/jingtan.wang/python-virtual-environments/xgboost/lib/libxgboost.dylib
INFO:XGBoost build_ext:运行 CMake 命令: [‘cmake’, ‘xgboost’, ‘-GUnix Makefiles’, ‘-DUSE_OPENMP=1’, ‘-DUSE_CUDA=0’, ‘-DUSE_NCCL=0’, ‘-DBUILD_WITH_SHARED_NCCL=0’, ‘-DHIDE_CXX_SYMBOLS=1’, ‘-DUSE_HDFS=0’, ‘-DUSE_AZURE=0’, ‘-DUSE_S3=0’, ‘-DPLUGIN_LZ4=0’, ‘-DPLUGIN_DENSE_PARSER=0’]
错误:[Errno 2] No such file or directory: ‘cmake’
我很抱歉听到这个消息。也许可以尝试在 stackoverflow 或 xgboost 项目的 github issues 上发帖/搜索?
你好,谢谢你的分享。我在第二部分遇到了一个问题。
我找不到解决这个问题的办法。我使用的是 Catalina,想知道这是否是问题的一部分?我确实看到了您之前对别人关于通过 port 或 brew 安装 make 的帖子的评论。Brew 在我的系统上反复失败(互联网超时问题)。您是否知道如何通过 macports 安装 make?
非常感谢!
Danielles-MacBook-Pro:Desktop danielleturvill$ cd xgboost/
Danielles-MacBook-Pro:xgboost danielleturvill$ cp make/config.mk ./config.mk
cp: make/config.mk: No such file or directory
Danielles-MacBook-Pro:xgboost danielleturvill$ ls
CITATION README.md gputreeshap
CMakeLists.txt amalgamation include
CONTRIBUTORS.md appveyor.yml jvm-packages
Jenkinsfile cmake plugin
Jenkinsfile-win64 cub python-package
LICENSE demo rabit
Makefile dev src
NEWS.md dmlc-core tests
R-package doc
较新版本似乎确实会引起问题。我建议使用旧版本的 XGBoost,例如 1.0.2。
您可以直接签出此版本,或通过 pip 直接安装它,例如:
嗨,Jason,
我一直在我的 MacOS Mojave(10.14.6) 上尝试安装集成 GPU 支持的 xgboost,已经 3 天了,但都没有成功。我尝试了 2 种方法:
1. pip install xgboost
xgboost 在这里安装成功,并且在没有 GPU 选项(即没有 tree_method='gpu_hist')的情况下运行正常。
我想通过在 tree 参数中指定“tree_method='gpu_hist'”来运行 gpu_hist。当我指定“tree_method='gpu_hist'”时,出现了以下错误:
XGBoostError: [12:10:34] /Users/travis/build/dmlc/xgboost/src/gbm/../common/common.h:153: XGBoost version not compiled with GPU support.
堆栈跟踪
[bt] (0) 1 libxgboost.dylib 0x000000012256ba60 dmlc::LogMessageFatal::~LogMessageFatal() + 112
[bt] (1) 2 libxgboost.dylib 0x00000001225f92b3 xgboost::gbm::GBTree::ConfigureUpdaters() + 531
[bt] (2) 3 libxgboost.dylib 0x00000001225f8b97 xgboost::gbm::GBTree::Configure(std::__1::vector<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator >, std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator >, std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > > > > const&) + 967
[bt] (3) 4 libxgboost.dylib 0x0000000122611a0c xgboost::LearnerConfiguration::Configure() + 1500
[bt] (4) 5 libxgboost.dylib 0x0000000122611e68 xgboost::LearnerImpl::UpdateOneIter(int, std::__1::shared_ptr) + 120
[bt] (5) 6 libxgboost.dylib 0x000000012256331d XGBoosterUpdateOneIter + 157
[bt] (6) 7 libffi.7.dylib 0x0000000102102ead ffi_call_unix64 + 85
[bt] (7) 8 ??? 0x00007ffeee291da0 0x0 + 140732894092704
2. 我的第二个方法
git clone –recursive https://github.com/dmlc/xgboost
cd xgboost/
make -j4
cd python-package
python3 setup.py install
虽然它安装了 xgboost,但在运行此语句时会抛出以下错误:
dtrain=xgb.DMatrix(df_train_features,label=df_train_label)#,missing=-999)
AttributeError: dlsym(0x7ffe9aed62f0, XGDMatrixSetDenseInfo): symbol not found
您能帮我安装支持 GPU 的 xgboost 吗?
尝试签出旧版本,例如 1.0.1。
我发现旧版本更容易编译,并且效果一样好。
Jason,xgboost 1.0.1 已通过 ‘pip install xgboost==1.0.1’ 安装。并且运行正常。
但是,它不支持 GPU,而我想安装支持 GPU 的 xgboost。
当我运行 xgboost 并使用 tree_method='gpu_hist' 时,我收到了以下错误:
(import xgboost as xgb
bst=xgb.XGBClassifier(n_estimators=20, max_depth=9, learning_rate=0.05,n_jobs=4,gamma=5,min_child_weight=20, eval_metric=’rmse’, missing=-999, tree_method=’gpu_hist’)
)
XGBoostError: [15:58:10] /private/var/folders/4n/s3z85_zs0z7_12y8mmg2yqd00000gn/T/pip-install-xq6d26qe/xgboost_a072b8d552e84085a86dcf21271bcc77/xgboost/include/xgboost/gbm.h:166: XGBoost version not compiled with GPU support.
您能帮我安装支持 GPU 的 xgboost 吗?
抱歉,我不是 XGBoost GPU 支持方面的专家,也许可以直接联系 XGBoost 的开发者,例如在他们的 github 项目上发帖提问。