Window下XGBoost安装
Posted snail_gesture
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Window下XGBoost安装相关的知识,希望对你有一定的参考价值。
本文主要是对XGBoost安装进行介绍。
在正文开始前,需要安装一些前置软件如下:
- Git
- MINGW
下面开始正文介绍。
1.首先创建XGBoost安装目录文件,然后在该目录下面启动git bash.
E:\\Xgboost
2.然后执行如下命令。
$ git clone --recursive https://github.com/dmlc/xgboost
$ cd xgboost
$ git submodule init
$ git submodule update
3.下载MinGW-W64,然后安装。
4.这里需要修改Architecture值为x86_64,因为我的本机是64位操作系统。
5.这里安装在我们前面创建的文件目录下面。
6.然后将mingw64\\bin配置到path中,然后重启bash,检验是否安装成功.
$ which mingw32-make
/e/Xgboost/mingw-w64/x86_64-7.1.0-posix-seh-rt_v5-rev1/mingw64/bin/mingw32-make
7.取别名
$ alias make='mingw32-make'
8.逐个编译各个模块
$ cd xgboost/
$ pwd
/e/Xgboost/xgboost
$ cd dmlc-core
$ make -j4
$ cd ../rabit
$ make lib/librabit_empty.a -j4
$ cd ..
$ cp make/mingw64.mk config.mk
$ make -j4
9.然后打开xgboost的python-package
$ cd python-package/
$ pwd
/e/Xgboost/xgboost/python-package
10.安装
/e/Xgboost/xgboost/python-package/python setup.py install
11.打开cmd,启动python,然后在命令行中加入如下内容。
import os
mingw_path = 'E:\\\\Xgboost\\\\mingw-w64\\\\x86_64-7.1.0-posix-seh-rt_v5-rev1\\\\mingw64\\\\bin'
os.environ['PATH'] = mingw_path + ';' + os.environ['PATH']
12.验证是否安装成功.
>>> import xgboost as xgb
>>> dtrain = xgb.DMatrix('E:/data/agaricus.txt.train')
[19:30:53] 490x127 matrix with 10780 entries loaded from E:/data/agaricus.txt.train
>>> dtest = xgb.DMatrix('E:/data/agaricus.txt.test')
[19:31:19] 177x127 matrix with 3894 entries loaded from E:/data/agaricus.txt.test
>>> param = 'max_depth':2, 'eta':1, 'silent':1, 'objective':'binary:logistic'
>>> num_round = 2
>>> bst = xgb.train(param, dtrain, num_round)
>>> # make prediction
... preds = bst.predict(dtest)
>>>
>>> preds
array([ 0.0432693, 0.9445464, 0.0432693, 0.0432693, 0.0432693,
0.0432693, 0.9445464, 0.0432693, 0.9445464, 0.0432693,
0.9445464, 0.0432693, 0.0432693, 0.0432693, 0.0432693,
0.0432693, 0.0432693, 0.9445464, 0.0432693, 0.0432693,
0.0432693, 0.0432693, 0.0432693, 0.0432693, 0.0432693,
0.9445464, 0.0432693, 0.0432693, 0.0432693, 0.0432693,
.........
参考文献:
https://www.ibm.com/developerworks/community/blogs/jfp/entry/Installing_XGBoost_For_Anaconda_on_Windows?lang=zh
https://xgboost.readthedocs.io/en/latest/build.html
https://xgboost.readthedocs.io/en/latest/get_started/
https://github.com/dmlc/xgboost/tree/master/demo/data
以上是关于Window下XGBoost安装的主要内容,如果未能解决你的问题,请参考以下文章