用 C++ 读取 XGBoost 模型

编程入门 行业动态 更新时间:2024-10-28 21:23:24
本文介绍了用 C++ 读取 XGBoost 模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送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:关键词]

本文发布于:2023-04-28 18:13:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1176865.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:模型   XGBoost

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!