注意objective 和eval_metric
使用xgboost 进行learning to rank
train_dmatrix = xgb.DMatrix(train.drop(['group','排名','score','Promotion'], axis=1),label=train['score'])
test_dmatrix = xgb.DMatrix(test.drop(['group','排名','score','Promotion'], axis=1),label=test['score'])
#设置训练集的group,将训练集按group排序,设置group为该group中行的个数,而不是编号,需满足 sum(train_group) = len(train)
train_dmatrix.set_group(train_group)
test_dmatrix.set_group(test_group)
params = {'booster':'gbtree',
'objective': 'rank:ndcg',
'eta': 0.1,
'max_depth': 6,
'silent':1,
'verbose':10,
'eval_metric':'ndcg@20-'}
xgb_model = xgb.train(params, train_dmatrix, num_boost_round=2000,
evals=[(train_dmatrix, 'train'),(test_dmatrix, 'test')],early_stopping_rounds=50)
网友评论