安装XGBoost-Python
pip install xgboost --index https://pypi.mirrors.ustc.edu.cn/simple/
安装基本开发工具:
$ sudo apt install git build-essential python-dev python-setuptools python-pip python-numpy python-scipy
1
|
$
git
clone
--
recursive
https
:
/
/
github
.com
/
dmlc
/
xgboost
|
编译:
1
2
|
$
cd
xgboost
$
make
-
j4
|
生成的库:lib/libxgboost.so、lib/libxgboost.a;命令行工具:xgboost。
安装Python包:
1
2
3
4
|
$
cd
python
-
package
/
$
sudo
python
setup
.py
install
# 或
# $ sudo python setup.py install --user
|
测试:
1
2
3
4
5
6
7
8
9
10
|
import
xgboost
as
xgb
# read in data
dtrain
=
xgb
.
DMatrix
(
'demo/data/agaricus.txt.train'
)
dtest
=
xgb
.
DMatrix
(
'demo/data/agaricus.txt.test'
)
# specify parameters via map
param
=
{
'max_depth'
:
2
,
'eta'
:
1
,
'silent'
:
1
,
'objective'
:
'binary:logistic'
}
num_round
=
2
bst
=
xgb
.
train
(
param
,
dtrain
,
num_round
)
# make prediction
preds
=
bst
.
predict
(
dtest
)
|
安装XGBoost-R
安装XGBoost包:
1
2
|
>
install
.
packages
(
'xgboost'
)
>
library
(
xgboost
)
|
测试:
1
2
3
4
5
6
7
8
9
|
# load data
data
(
agaricus
.
train
,
package
=
'xgboost'
)
data
(
agaricus
.
test
,
package
=
'xgboost'
)
train
<
-
agaricus
.
train
test
<
-
agaricus
.
test
# fit model
bst
<
-
xgboost
(
data
=
train
$
data
,
label
=
train
$
label
,
max
.
depth
=
2
,
eta
=
1
,
nround
=
2
,
nthread
=
2
,
objective
=
"binary:logistic"
)
# predict
pred
<
-
predict
(
bst
,
test
$
data
)
|
- XGBoost源代码:https://github.com/dmlc/xgboost
- XGBoost的文档:http://xgboost.readthedocs.io/en/latest/