/xgboostpredictor

C++ header-only thread-safe XGBoost predictor

Primary LanguageC++Apache License 2.0Apache-2.0

XGBoostPredictor

C++ header-only thread-safe library of XGBoost predictor without dependency on xgboost library.

Requirements

  • C++17 compiler
  • RapidJSON library installed
  • XGBoost model saved to json format (requires xgboost >= 1.0)

Using library in C++

#include "xgboostpredictor.h"
#include <iostream>

using namespace xgboost::predictor;

int main()
{
    // load xgboost json model
    XGBoostPredictor predictor("model.json");

    // prepare features (3 features total)
    XGBoostPredictor::Data data(3);

    // set features
    // NOTE: feature 0 is set to 1.2, feature 1 is missing and feature 2 is set to 3.4
    data[0] = 1.2f;
    data[2] = 3.4f;
    
    // make prediction
    const auto prediction = predictor.predict(data);

    // print predicted value
    std::cout << prediction[0] << std::endl;
}