Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- from xgboost import XGBClassifier
- model = XGBClassifier(use_label_encoder=False)
- model.fit(np.array([[1,2],[3,4]]), np.array([0,1]))
- model.save_model("model.bin")
- ############
- #include <iostream>
- #include "xgboost/c_api.h"
- #define safe_xgboost(call) \
- { \
- int err_code = (call); \
- if (err_code != 0) { \
- std::string error = XGBGetLastError(); \
- std::cerr << "Error during " << #call << ":" << error << std::endl; \
- exit(1); \
- } \
- }
- int main() {
- void* booster_handle_ = nullptr;
- safe_xgboost(XGBoosterCreate(nullptr, 0, &booster_handle_));
- safe_xgboost(XGBoosterLoadModel(booster_handle_, "model.bin"));
- safe_xgboost(XGBoosterSetParam(booster_handle_, "nthread", "1"));
- if (booster_handle_ != nullptr) {
- safe_xgboost(XGBoosterFree(booster_handle_));
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement