2019-11-19:xgboost用于排序的算法
2019-11-19 本文已影响0人
AI_Finance
def train_pairwise(self):
""" train and predict ranking model with pairwise mode """
X, Y, indices, _ = self.prepare_data(root_dir+"/data/pairwise_data/train_features.txt.%s" % self.args.task_purpose)
dtrain = xgb.DMatrix(X, label=Y)
dtrain_group = self.load_group_file(root_dir+"/data/pairwise_data/train_features.txt.%s.group" % self.args.task_purpose)
dtrain.set_group(dtrain_group)
params = {"objective": "rank:pairwise",
"min_child_weight": 1,
"eta": 0.1,
"gamma": 1.0,
"max_depth": 20}
watchlist = [(dtrain, 'train')]
num_round = 5000
self.bst = xgb.train(params, dtrain, num_round, watchlist)