Creating xgboost Dmatrix in C ++

I would like to use xgboost to classify images in a C ++ project. I have an attribute matrix (hist) cv :: Mat_ and a label vector, std :: vector, how can I create xgboost :: DMatrix in C ++? I think I should use DMatrix :: Create (), but I do not understand what parameters I should pass.

std::vector<int> labels; //read this labels from csv
auto features = extract_features(img_ident, dir); 
cv::Mat_<float> training_set(features);

xgboost::DMatrix xgb_data = xgboost::DMatrix::Create(????);
+4
source share
1 answer

Use c_api:

DMatrixHandle xgbData;
int success = XGDMatrixCreateFromMat(&features[0], m_nRowCount, m_nColCount, 0, &xgbData);
if(success != 0)
  THROW_ERROR("Error creating DMatrix\n");

success = XGDMatrixSetFloatInfo(xgbData, "label", &matrixYLabels[0], m_nRowCount);
if(success != 0)
  THROW_ERROR("Error setting Y values in DMatrix\n");

success = XGDMatrixSaveBinary(xgbData, filename, false);
if(success != 0)
  THROW_ERROR("Error saving DMatrix\n");
-1
source

Source: https://habr.com/ru/post/1627936/


All Articles