How to install XGBoost on OSX with multi-threading
我正在尝试按照此处的指南在我的 mac (osx 10.12.1) 上安装 xgboost,但我遇到了一些问题。
步骤1
Obtain gcc-6.x.x with openmp support by
brew install gcc –without-multilib
终端
1
2 3 4 5 6 7 8 9 10 11 |
Ben$ brew install gcc —without–multilib Error: gcc–5.3.0 already installed To install this version, first `brew unlink gcc` Ben$ brew unlink gcc Ben$ brew install gcc —without–multilib |
第2步
Clone the repository
git clone –recursive https://github.com/dmlc/xgboost
终端
1
2 3 4 5 6 7 8 9 10 11 12 13 14 |
Ben$ git clone —recursive https://github.com/dmlc/xgboost
Cloning into ‘xgboost’… remote: Counting objects: 18754, done. remote: Compressing objects: 100% (21/21), done. remote: Total 18754 (delta 1), reused 0 (delta 0), pack–reused 18733 Receiving objects: 100% (18754/18754), 6.23 MiB | 3.74 MiB/s, done. Resolving deltas: 100% (11347/11347), done. Checking connectivity… done. Submodule ‘dmlc-core’ (https://github.com/dmlc/dmlc-core) registered for path ‘dmlc-core’ Submodule ‘rabit’ (https://github.com/dmlc/rabit) registered for path ‘rabit’ Cloning into ‘/Users/Ben/xgboost/dmlc-core’… Cloning into ‘/Users/Ben/xgboost/rabit’… Submodule path ‘dmlc-core’: checked out ‘f35f14f30835af238257b979cc1fac3e41ff3291’ Submodule path ‘rabit’: checked out ‘a9a2a69dc1144180a43f7d2d1097264482be7817’ |
第三步
build using the following commands
cd xgboost; cp make/config.mk ./config.mk; make -j4 NOTE: If you use OSX El Capitan, brew installs gcc the latest version gcc-6. So you may need to modify Makefile#L46 and change gcc-5 to gcc-6. After that change gcc-5/g++-5 to gcc-6/g++-6 in make/config.mk then build using the following commands
嗯。不完全确定在这里做什么。我在
生成文件(片段)
1
2 3 4 5 6 7 |
# on Mac OS X, force brew gcc-6, since the Xcode c++ fails anyway
# it is useful for pip install compiling-on-the-fly OS := $(shell uname) ifeq ($(OS), Darwin) export CC = $(if $(shell which gcc–6),gcc–6,$(if $(shell which gcc–mp–6), gcc–mp–6, clang)) export CXX = $(if $(shell which g++-6),g++-6,$(if $(shell which g++-mp–6),g++-mp–6, clang++)) endif |
将忽略这一点并继续前进……
终端
1
2 3 4 |
Ben$ cd xgboost; cp make/config.mk ./config.mk; make –j4
[Tons of log output. Appears to finish succesfully] … g++-6 –std=c++0x –Wall –O3 –msse2 –Wno–unknown–pragmas –funroll–loops –Iinclude –Idmlc–core/include –Irabit/include –fPIC –fopenmp –shared –o lib/libxgboost.so build/learner.o build/logging.o build/c_api/c_api.o build/c_api/c_api_error.o build/common/common.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/tree/tree_model.o build/tree/tree_updater.o build/tree/updater_colmaker.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 |
Step4(这里有说明吗?)
If you would like to use the latest xgboost version and already
compiled xgboost, uselibrary(devtools); install(‘xgboost/R-package’)
to install manually xgboost package (change the path accordingly to
where you compiled xgboost).
新的 R 会话
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
library(devtools) install("/Users/Ben/xgboost/R-package") Installing xgboost * installing *source* package a€?xgboosta€? … |
失败:(我哪里出错了?
更新的解决方案
截至 2019 年 3 月,R 版本 3.5.3,xgboost 版本 0.82.0.1,与我的旧答案相比,情况发生了变化。以下步骤基于此处的安装指南,但略有不同。
现在重启/刷新 RStudio,它应该已经安装好了
在 R 中测试
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 |
set.seed(222) N <– 2*10^5 p <– 350 x <– matrix(rnorm(N * p), ncol = p) y <– rnorm(N) system.time(mymodel <– xgboost( # Tested on 2018 MPB, xgboost version 0.82.0.1, multi-threaded version |
旧答案
令人惊讶的是,在 StackOverflow 上写下您的问题通常会直接引导您找到答案。在花了几个小时之后,我发现我需要在
中更改这三行
1
2 3 |
CC=gcc–5
CXX=g++-5 CXX1X = g++-5 |
到
1
2 3 |
CC=gcc–6
CXX=g++-6 CXX1X = g++-6 |
另外,我最终从”drat”仓库安装了 xgboost
1
2 3 |
install.packages("drat", repos="https://cran.rstudio.com")
drat:::addRepo("dmlc") install.packages("xgboost", repos="http://dmlc.ml/drat/", type ="source") |
我的方法是在您的第一个(更新 gcc)和第二个(克隆)步骤之后,无需构建任何东西(它们适用于其他语言,如 python)
3) 更新 ~/.R/Makevars
https://github.com/dmlc/xgboost/issues/1136
如何使 R 包 xgboost 在 OS X 中与 OpenMP 编译并行?
4) 从克隆 xgboost/R-package/configure 将
https://github.com/dmlc/xgboost/issues/2503
5) 在 xgboost/R 封装类型
http://xgboost.readthedocs.io/en/latest/build.html#r-package-installation
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/268865.html