第一步:安装最新版的xgboost
打开终端输入:
git clone --recursive https://github.com/dmlc/xgboost
cd xgboost; make -j4
第二步:安装Python package
1、cd 到 python-package目录
sudo apt-get install python-setuptools2、添加环境变量
在根目录下Crtl+h 显示隐藏文件 ~/.bashrc
加入环境变量
export PYTHONPATH=~/xgboost/python-package第三步:安装R package
git clone --recursive https://github.com/dmlc/xgboost cd xgboost make Rbuild R CMD INSTALL xgboost_0.4-3.tar.gz
还可以用第二种方法:先安装R环境:sudo apt-get install r-base=core在终端输入-R> install.packages('xgboost') > library(xgboost)下面是简单的二分类的例子第一步:准备训练数据cd xgboost/demo/binary_classification python mapfeat.py python mknfold.py agaricus.txt 1
会生成<span style="color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; line-height: 25.6000003814697px;"> 'agaricus.txt.train' and 'agaricus.txt.test'</span>
<span style="color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; line-height: 25.6000003814697px;">第二步:训练</span>
<span style="color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; line-height: 25.6000003814697px;"></span><pre name="code" class="html" style="color: rgb(64, 64, 64);">cd xgboost/demo/binary_classification
../../xgboost mushroom.conf
会生成一个****.model的分类器
第三步:预测
<pre name="code" class="html" style="color: rgb(64, 64, 64);"><span style="color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; line-height: 25.6000003814697px;"></span><pre name="code" class="html" style="color: rgb(64, 64, 64);">cd xgboost/demo/binary_classification
../../xgboost mushroom.conf <span style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; line-height: inherit; color: rgb(51, 51, 51); font-size: 14px; white-space: nowrap; background-color: transparent;">task=pred model_in=****.model</span>