XGBoost的GPU加速插件

XGBoost是诸如Kaggle等数据科学竞赛选手的利器。在特征属于许多不同范畴时,XGBoost的表现通常优于神经网络,因此它适合用于组合手工构造的特征。

在特征较多,样本较多时,XGBoost的训练也会比较慢,我们可以考虑使用GPU进行加速。

GPU加速插件安装

安装GPU加速插件时需要重新编译XGBoost,在编译时指定相应选项。

  • 首先从github上clone整个repo的代码
git clone --recursive [https://github.com/dmlc/xgboost.git](https://github.com/dmlc/xgboost.git)
  • 不同的操作系统编译方式不同,详见此处
    在Linux系统下
cd xgboost
mkdir build
cd build
cmake .. -DPLUGIN_UPDATER_GPU=ON
make -j
  • 编译完成后,生成libxgboostXX.so,接着安装xgboost的python包,Linux下
cd python-package
sudo python setup.py install

GPU加速插件的使用

设置tree_methodgpu_exactgpu_hist即可。

也可以调整使用的GPU数目和次序,例如

param['tree_method'] = 'gpu_hist'
param['n_gpus'] = -1 # -1表示使用所有GPU
param['gpu_id'] = 1 # 从GPU 1 开始

常用参数如下所示

XGBoost的GPU加速插件_第1张图片
gpu插件相关参数

你可能感兴趣的:(XGBoost的GPU加速插件)