-->

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

2019-06-03 17:24发布

问题:

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.



标签: c# c++ r pmml gbm