您好,登录后才能下订单哦!
这篇文章主要介绍“linux下c++怎么集成LightGBM模型进行预测”的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇“linux下c++怎么集成LightGBM模型进行预测”文章能帮助大家解决问题。
(1)lightGBM源码 提取码:qab2
(2)cmake 提取码:3sdn
(3)环境:centos7
操作系统已经按照g++和gcc编译工具,可使用命令进行安装
yum install gcc
yum install gcc-c++
本次操作目录均在/root/test,如下图所示:
(1) 输入命令:tar -zxvf cmake-3.18.4.tar.gz 解压cmake.tar.gz
(2) 进入cmake-3.18.4文件夹并执行./configure命令
按照过程中如果报了“Could not find OpenSSL. Install an OpenSSL development package or”,需要先执行yum instal openssl和yum install openssl-devel再执行./configure命令
(3) 执行命令gmake
(4) 执行命令确认cmake的版本,确认cmake是否成功安装
#include <LightGBM/c_api.h>#include <iostream>#include <vector>void predict(std::vector<float> &row){std::string pred_result = "";int temp;int p = 1;BoosterHandle handle;temp = LGBM_BoosterCreateFromModelfile("models/3_300_gbm.txt", &p, &handle);std::cout << "load result value is " << temp << std::endl;// std::vector<float> row = {0.07946399999999999, 0.9537260000000001, 0.9621209999999999, 0.976303, 7.0, 3.0};for (auto value : row)std::cout << value << ",";std::cout << std::endl;void *in_p = static_cast<void *>(row.data());std::vector<double> out(1, 0);double *out_result = static_cast<double *>(out.data());int64_t out_len;int res = LGBM_BoosterPredictForMat(handle, in_p, C_API_DTYPE_FLOAT32, 1, 6, 1, C_API_PREDICT_NORMAL, 0, -1, "None", &out_len, out_result);std::cout << "file predict result is:" << res << std::endl;std::cout << "row predict result size is " << out.size() << " value is " << out[0] << std::endl;}int main(){std::vector<float> row = {0.07946399999999999, 0.9537260000000001, 0.9621209999999999, 0.976303, 7.0, 3.0};predict(row);std::cout << std::endl;std::vector<float> row1 = {0.910457, 0.692459, 0.8338110000000001, 0.78886, 14.0, 10.0};predict(row1);std::cout << "Ok complete!" << std::endl;return 0;}// g++ -g -Wall -std=c++11 test.cpp -l_lightgbm -Wl,-R /usr/local/lib -o test// g++ -g -Wall -std=c++11 test.cpp -l_lightgbm -Wl,-R /root/moead/models -L/ydq/moead/models -I/root/moead/models/include -o test
关于“linux下c++怎么集成LightGBM模型进行预测”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识,可以关注亿速云行业资讯频道,小编每天都会为大家更新不同的知识点。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。