LoginSignup
4
4

More than 5 years have passed since last update.

XGBoostをMac, CentOSにインストールする

Last updated at Posted at 2016-10-10

概要

scikit-learnのgbmより早くて性能が高いと言われるXBGoostをMac, CentOSにインストールする。

Macへのインストール

依存ライブラリclang-ompのインストール

$ brew tap homebrew/boneyard
$ brew install clang-omp

XGBoostのインストール

$ pip3 install xgboost

CentOSへのインストール

gccのアップデート

通常だとgcc 4.4のままなので、XGBoostのコンパイルに必要な4.6以上である4.8にアップデートする。

$ wget http://people.centos.org/tru/devtools-2/devtools-2.repo -O /etc/yum.repos.d/devtools-2.repo  
$ yum install devtoolset-2-gcc devtoolset-2-binutils devtoolset-2-gcc-c++  

Error: database disk image is malformedとなってインストールに失敗する場合は、yum clean allを実行。

パスの切り替え

/opt/rh/devtoolset-2/root/usr/bin/にインストールされているため、一時的にパスを切り替える。

$ scl enable devtoolset-2 bash  

XGBoostのインストール

$ pip3 install xgboost  

使用例

python3
from xgboost import XGBRegressor
from sklearn import datasets
from sklearn.model_selection import train_test_split
from sklearn.metrics import r2_score

diabetes = datasets.load_diabetes()
X = diabetes.data
y = diabetes.target

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=0)

clf = XGBRegressor()
clf.fit(X_train, y_train)
pred = clf.predict(X_test)

print('r2 = {}'.format(r2_score(y_test, pred)))


import matplotlib.pyplot as plt
%matplotlib inline

plt.grid()
plt.scatter(y_test, pred)
plt.show()

スクリーンショット 2016-10-10 21.26.31.png

References

4
4
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
4
4