Using XGBOOST in c++

前端 未结 6 1637
谎友^
谎友^ 2020-12-13 01:14

How can I use XGBOOST https://github.com/dmlc/xgboost/ library in c++? I have founded Python and Java API, but I can\'t found API for c++

6条回答
  •  春和景丽
    2020-12-13 01:40

    Here is what you need:https://github.com/EmbolismSoil/xgboostpp

    #include "xgboostpp.h"
    #include 
    #include 
    
    int main(int argc, const char* argv[])
    {
        auto nsamples = 2;
        auto xgb = XGBoostPP(argv[1], 3); //特征列有4列, label有3个, iris例子中分别为三种类型的花,回归任何的话,这里nlabel=1即可
    
        //result = array([[9.9658281e-01, 2.4966884e-03, 9.2058454e-04],
        //       [9.9608469e-01, 2.4954407e-03, 1.4198524e-03]], dtype=float32)
        XGBoostPP::Matrix features(2, 4);
        features <<
            5.1, 3.5, 1.4, 0.2,
            4.9, 3.0, 1.4, 0.2;
    
        XGBoostPP::Matrix y;
        auto ret = xgb.predict(features, y);
        if (ret != 0){
            std::cout << "predict error" << std::endl;
        }
    
        std::cout << "intput : \n" << features << std::endl << "output: \n" << y << std::endl;
    }
    

提交回复
热议问题