xgboost 101

Posted by c cm on April 1, 2016

安装

Mac El Captain下安装xgboost:

  1. git clone --recursive https://github.com/dmlc/xgboost
  2. cd xgboost; cp make/minimum.mk ./config.mk; make -j4
  3. cd python-package/
  4. 注释掉setup.py中的include_package_data=True
  5. sudo python setup.py install # 这样以后在ipynb中就能用了
  6. cd xgboost; touch VERSION

doc

Starter Code

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)

DMatrix(some_pd_DataFrame, label=)

重要的param
“objective”:”count:poisson”, #分类/回归/排序等
“eval_metric”:[ “mae”]