0
votes

I have data frame with external regressors - x and vector of dependent variable - response. I want to train xgboost model. What should i put in for label in xgboost function? Or my way of constructing suitable input is wrong at all?

g <- data.frame(target = response,x)
sm <-sparse.model.matrix(target ~., g) 
fit <- xgboost (data = sm, 
                label = , 
                eta = 0.1,
                max_depth = 15, 
                nround=25, 
                subsample = 0.5,
                colsample_bytree = 0.5,
                seed = 1,
                eval_metric = "merror",
                objective = "reg:linear",
                num_class = 12,
               nthread = 3
    )

Thanks in advance!

1
Check out the documentation and examples, ?xgboost. "label: vector of response values." So use label = g$target. - Gregor Thomas
when i do as you adviced such error appears :Error in xgb.iter.update(bst$handle, dtrain, iteration - 1, obj) : [10:33:15] amalgamation/../src/objective/regression_obj.cc:90: Check failed: (preds.size()) == (info.labels.size()) labels are not correctly providedpreds.size=1752, label.size=146 - John Doe

1 Answers

0
votes
# X_train is train samples,, y_train is train label
# X_test is test samples
# this function ,you nedd to write by youself!
X_train, y_train = featureSet(data)
X_test = loadTestData(testFilePath)

dtrain = xgb.DMatrix(X_train, y_train)
num_rounds = 300
plst = params.items()
model = xgb.train(plst, dtrain, num_rounds)

# 对测试集进行预测
dtest = xgb.DMatrix(X_test)
ans = model.predict(dtest)