這篇文章主要介紹“l(fā)inux下c++怎么集成LightGBM模型進行預(yù)測”的相關(guān)知識,小編通過實際案例向大家展示操作過程,操作方法簡單快捷,實用性強,希望這篇“l(fā)inux下c++怎么集成LightGBM模型進行預(yù)測”文章能幫助大家解決問題。
老城網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián),老城網(wǎng)站設(shè)計制作,有大型網(wǎng)站制作公司豐富經(jīng)驗。已為老城上1000家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\成都外貿(mào)網(wǎng)站建設(shè)公司要多少錢,請找那個售后服務(wù)好的老城做網(wǎng)站的公司定做!
(1)lightGBM源碼 提取碼:qab2
(2)cmake 提取碼:3sdn
(3)環(huán)境:centos7
操作系統(tǒng)已經(jīng)按照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文件夾并執(zhí)行./configure命令
按照過程中如果報了“Could not find OpenSSL. Install an OpenSSL development package or”,需要先執(zhí)行yum instal openssl和yum install openssl-devel再執(zhí)行./configure命令
(3) 執(zhí)行命令gmake
(4) 執(zhí)行命令確認cmake的版本,確認cmake是否成功安裝
#include#include #include void predict(std::vector &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 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 (row.data());std::vector out(1, 0);double *out_result = static_cast (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 row = {0.07946399999999999, 0.9537260000000001, 0.9621209999999999, 0.976303, 7.0, 3.0};predict(row);std::cout << std::endl;std::vector 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
關(guān)于“l(fā)inux下c++怎么集成LightGBM模型進行預(yù)測”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識,可以關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,小編每天都會為大家更新不同的知識點。