Coder Social home page Coder Social logo

xgb2cpp's Introduction

xgb2cpp

xgb2cpp converts XGBoost raw text dump to C++ code that you can use in your C++ projects.

READ FIRST

This code (atm) only works on XGB models trained with 'multi:softprob' objective. 'multi:softprob' objective tells XGBoost to train trees in "1 vs. all" fashion. If you want it to work with 'binary:logistic' or 'binary:logitraw' you'll have to tweak code-generating Python script a bit or wait for me to implement it.

How to run it?

Use generate_cpp_code.py script to generate xgboost_classifier.cpp. Generated xgboost_classifier.cpp will contain xgb_classify() function that you can use to classify samples. In folder sample you can find main.cpp and xgboost_classifier.h files that form use case project.

Also, there is a pima-indian-diabetes dataset that I used to generate dummy model. File /sample/pima-indians-diabetes/train.py trains XGB model and creates dump.raw.txt which is raw text representation of trained model.

Example run:

cd sample/pima-indians-diabetes
# Train model and generate dump.raw.txt
python train.py
cd ../../
# Generate xgboost_classifier.cpp
python python generate_cpp_code.py --num_classes=2 --xgb_dump=sample/pima-indians-diabetes/dump.raw.txt
# Copy xgboost_classifier.cpp to sample project
cp xgboost_classifier.cpp sample/codeblocks_project/xgboost_classifier.cpp
# Now build and run main.cpp, xgboost_classifier.cpp and xgboost_classifier.h in sample/codeblocks_project

If you have any questions or improvements just open issue and I'll be on it. Thanks

xgb2cpp's People

Contributors

drag0 avatar popcorn avatar

Watchers

James Cloos avatar Liping Zhang avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.