我想在c ++项目中使用xgboost进行图像分类。我有特征矩阵(hist)cv :: Mat_和标签矢量,std :: vector,如何在c ++中创建xgboost :: DMatrix?我想我应该使用DMatrix :: Create(),但我不明白我应该传递哪些参数。
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(????);
答案 0 :(得分:0)
使用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");