Search code examples
xgboost

How to pass label to matrix of XGBoost JVM Package


I found the JVM package quick start example of creating data matrix at official doc

float[] data = new float[] {1f,2f,3f,4f,5f,6f};
int nrow = 3;
int ncol = 2;
float missing = 0.0f;
DMatrix dmat = new DMatrix(data, nrow, ncol, missing);

// and a DMatrix could be called by train method
Booster booster = XGBoost.train(dmat, params, nround, watches, null, null);

However, the doc says the JVM package DMatrix usage is the same with Python package, in Python, there is a label parameter

dtrain = xgb.DMatrix(data, label=label)

But I could not find any in JVM package, how to set the label?


Solution

  • In XGBoost JVM package we could use dMatrix.setLabel(labelArray) to set the label (According to XGBoost github issue page)