问题描述
限时送ChatGPT账号..我使用 XGBoost 在 R 中训练了我的模型,现在需要在 C++ 中进行预测.我正在尝试使用 XGBoosterLoadModel
函数在 C++ 中加载模型文件.
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.
我的代码编译良好,但无法发现我的单元测试函数.当我删除对函数 XGBoosterLoadModel
的调用时,一切正常,我可以看到我的单元测试.
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);
}
}
推荐答案
您需要先分配句柄.这段代码对我有用:
You need to allocate your handle first. this code works for me:
BoosterHandle x;
XGBoosterCreate(0,0,&x);
int y = XGBoosterLoadModel(x,model_filename);
这篇关于用 C++ 读取 XGBoost 模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论