Deploy GBM Model in C++ | Get Predict.gbm to work outside of R

被刻印的时光 ゝ 提交于 2019-12-08 04:13:14

问题


Is there a way to export a gbm model to C++. Specifically, how do I invoke the predict.gbm function to run outside of R in order to score new datasets.

I have exported the model as a PMML file but I am unsure as to how new datasets will be scores based off the PMML.

I am new to R and have spent a lot of hours trying to figure this out to no avail and will appreciate any leads

Thanks in advance


回答1:


Here, PMML only helps you if you have a C++ based PMML evaluation engine available (alternatively, you might use C++ to invoke a Java based PMML evaluation engine such as the JPMML-Evaluator library).

You could translate GBM model to C++ source code and run it "natively" later on. The translation is not difficult, because GBM member decision trees can be encoded as simple if-else statements. You can see how it's implemented in the JPMML-Converter library (class org.jpmml.converter.GBMConverter) and take it from there.

Translation to PMML:

Node node = new Node()
  .withPredicate($predicate)
  .withScore($score);

Translation to C/C++/C#:

if($predicate){
   return $score;
}

You can export the GBM data structure from R to C++ conversion application using the ProtoBuf data format (as implemented by the RProtoBuf package). Again, please see how the JPMML-Converter library does it.



来源:https://stackoverflow.com/questions/28752797/deploy-gbm-model-in-c-get-predict-gbm-to-work-outside-of-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!