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

1

1

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

Williamwilliams answered 26/2, 2015 at 21:10 Comment(1)
Hi, did you ever find an execution engine written in C/C++?Hardshell
P
0

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.

Potation answered 27/2, 2015 at 8:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.