Reading XGBoost Model in C++

試著忘記壹切 提交于 2019-12-25 07:15:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!