這篇文章主要介紹“l(fā)inux下c++怎么集成LightGBM模型進(jìn)行預(yù)測(cè)”的相關(guān)知識(shí),小編通過(guò)實(shí)際案例向大家展示操作過(guò)程,操作方法簡(jiǎn)單快捷,實(shí)用性強(qiáng),希望這篇“l(fā)inux下c++怎么集成LightGBM模型進(jìn)行預(yù)測(cè)”文章能幫助大家解決問(wèn)題。
創(chuàng)新互聯(lián)主要從事網(wǎng)頁(yè)設(shè)計(jì)、PC網(wǎng)站建設(shè)(電腦版網(wǎng)站建設(shè))、wap網(wǎng)站建設(shè)(手機(jī)版網(wǎng)站建設(shè))、成都響應(yīng)式網(wǎng)站建設(shè)公司、程序開(kāi)發(fā)、網(wǎng)站優(yōu)化、微網(wǎng)站、微信小程序開(kāi)發(fā)等,憑借多年來(lái)在互聯(lián)網(wǎng)的打拼,我們?cè)诨ヂ?lián)網(wǎng)網(wǎng)站建設(shè)行業(yè)積累了豐富的成都網(wǎng)站制作、網(wǎng)站設(shè)計(jì)、網(wǎng)站設(shè)計(jì)、網(wǎng)絡(luò)營(yíng)銷(xiāo)經(jīng)驗(yàn),集策劃、開(kāi)發(fā)、設(shè)計(jì)、營(yíng)銷(xiāo)、管理等多方位專業(yè)化運(yùn)作于一體。(1)lightGBM源碼 提取碼:qab2
(2)cmake 提取碼:3sdn
(3)環(huán)境:centos7
操作系統(tǒng)已經(jīng)按照g++和gcc編譯工具,可使用命令進(jìn)行安裝
yum install gcc
yum install gcc-c++
本次操作目錄均在/root/test,如下圖所示:
(1) 輸入命令:tar -zxvf cmake-3.18.4.tar.gz 解壓cmake.tar.gz
(2) 進(jìn)入cmake-3.18.4文件夾并執(zhí)行./configure命令
按照過(guò)程中如果報(bào)了“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í)行命令確認(rèn)cmake的版本,確認(rèn)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模型進(jìn)行預(yù)測(cè)”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí),可以關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,小編每天都會(huì)為大家更新不同的知識(shí)點(diǎn)。