Window下XGBoost安装

来源:互联网 发布:mac os x 10.10 iso 编辑:程序博客网 时间:2024/05/16 18:14

本文主要是对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 osmingw_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)>>>>>> predsarray([ 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