Advertisement
Guest User

Untitled

a guest
Sep 1st, 2021
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.21 KB | None | 0 0
  1. import numpy as np
  2. from xgboost import XGBClassifier
  3.  
  4. model = XGBClassifier(use_label_encoder=False)
  5. model.fit(np.array([[1,2],[3,4]]), np.array([0,1]))
  6. model.save_model("model.bin")
  7.  
  8. ############
  9.  
  10. #include <iostream>
  11. #include "xgboost/c_api.h"
  12.  
  13. #define safe_xgboost(call)                                                \
  14.   {                                                                       \
  15.     int err_code = (call);                                                \
  16.     if (err_code != 0) {                                                  \
  17.       std::string error = XGBGetLastError();                              \
  18.       std::cerr << "Error during " << #call << ":" << error << std::endl; \
  19.       exit(1);                                                            \
  20.     }                                                                     \
  21.   }
  22.  
  23. int main() {
  24.   void* booster_handle_ = nullptr;
  25.   safe_xgboost(XGBoosterCreate(nullptr, 0, &booster_handle_));
  26.   safe_xgboost(XGBoosterLoadModel(booster_handle_, "model.bin"));
  27.   safe_xgboost(XGBoosterSetParam(booster_handle_, "nthread", "1"));
  28.   if (booster_handle_ != nullptr) {
  29.     safe_xgboost(XGBoosterFree(booster_handle_));
  30.   }
  31.   return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement