13
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【メモ】GoogleColab でXGBoost, LightGBM, CatBoost でGPUを使用する方法

Posted at
  • 製造業出身のデータサイエンティストがお送りする記事
  • 今回は、GoogleColab で勾配ブースティング決定木(XGBoost, LightGBM, CatBoost)でGPU を使う方法をメモとして残しておきます。

GPU を使えるようにする方法

XGBoost

  • パラメータtree_method='gpu_hist'を設定するだけです。
# XGBoost
import xgboost as xgb

model = xgb.XGBRegressor(**params, tree_method='gpu_hist')

LightGBM

  • LightGBM のGPU バージョンのライブラリーをインストールする必要があります。
!git clone --recursive https://github.com/Microsoft/LightGBM
%cd /content/LightGBM/
!mkdir build
!cmake -DUSE_GPU=1 
!make -j$(nproc)
!sudo apt-get -y install python-pip

!sudo -H pip install setuptools numpy scipy scikit-learn -U
%cd /content/LightGBM/python-package
!sudo python setup.py install --precompile
  • あとは、パラメータdevice_type='gpu'を設定するだけです。
# LightGBM
import lightgbm as lgb

model = lgb.LGBMRegressor(**params,device_type='gpu')

CatBoost

  • パラメータtask_type='GPU'を設定するだけです。
# CatBoost
import catboost as cb

model = cb.CatBoostRegressor(**params, task_type='GPU')
13
13
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?