Help us understand the problem. What is going on with this article?

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

More than 3 years have passed since last update.

概要

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

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away