def train_level1(self, select_param=False): self.l1_param = { "bst:max_depth": 10, "bst:min_child_weight": 4, "bst:subsample": 0.5, "bst:colsample_bytree": 0.8, "bst:eta": 0.05, } other = { "silent": 1, "objective": "multi:softprob", "num_class": 9, "nthread": 4, "eval_metric": "mlogloss", "seed": 0, } other["num_class"] = len(self.l1_lbl_enc.classes_) self.l1_num_round = 400 if select_param: results = otto_utils.select_xgb_params(self.l1_train, self.l1_labels, depth_range=(7, 12)) self.l1_results = results print results[0] self.l1_num_round = results[0][1] param = results[0][2] dtrain = xgb.DMatrix(self.l1_train, label=self.l1_labels) full_param = other.copy() full_param.update(self.l1_param) bst, loss, ntree = xgb.train(full_param, dtrain, self.l1_num_round, [(dtrain, "train")]) self.l1_model = bst pass
def train_level2(self, select_param=False): self.l2_models = [] self.l2_params = [] self.l2_num_rounds = [] self.l2_results = [] for i in xrange(len(self.cls_sets)): param = { "bst:max_depth": 10, "bst:min_child_weight": 4, "bst:subsample": 0.5, "bst:colsample_bytree": 0.8, "bst:eta": 0.05, } other = { "silent": 1, "objective": "multi:softprob", "num_class": 9, "nthread": 4, "eval_metric": "mlogloss", "seed": 0, } other["num_class"] = len(self.cls_sets[i]) num_round = 400 if select_param: results = otto_utils.select_xgb_params(self.l2_train[i], self.l2_labels[i], depth_range=(8, 13)) self.l2_results.append(results) print results[0] num_round = results[0][1] param = results[0][2] dtrain = xgb.DMatrix(self.l2_train[i], self.l2_labels[i]) self.l2_params.append(param) self.l2_num_rounds.append(num_round) full_param = other.copy() full_param.update(param) bst, loss, ntree = xgb.train(full_param, dtrain, num_round, [(dtrain, "train")]) self.l2_models.append(bst) pass