问题
I trained my model in R using XGBoost and now need to do predictions in C++. I am trying to load the model file in C++ using XGBoosterLoadModel
function.
My code compiles fine but it fails at discovering my unit-test functions. When I remove the call to function XGBoosterLoadModel
, everything works fine and I can see my unit tests.
Here's what I have in my unit test file. Any clue on what I'm missing would be really appreciated:
#include <xgboost/c_api.h>
#include "stdafx.h"
#include <google/gtest/gtest.h>
namespace UnitTests
{
TEST(XGBoost, HysteresisPeakDetection_WithEmptyInput_ReturnsFalse)
{
const char *fname;
BoosterHandle handle;
int a = XGBoosterLoadModel(handle, fname);
}
}
回答1:
You need to allocate your handle first. this code works for me:
BoosterHandle x;
XGBoosterCreate(0,0,&x);
int y = XGBoosterLoadModel(x,model_filename);
来源:https://stackoverflow.com/questions/38314092/reading-xgboost-model-in-c