3

Is it possible to generate PMML of a gbm model? When I try to use the pmml library, I get an error:

Error in UseMethod("pmml") : no applicable method for 'pmml' applied to an object of class "gbm"

Ideally, I'd like to export into PMML but I could live with another format I can parse programmatically.

Josh Marcus
  • 133
  • 6

1 Answers1

3

PMML makes sense if you want to deploy your model directly to a PMML scoring engine such as JPMML.

Otherwise, use generic serialization mechanisms. R lets you store and load data structures using built-in functions saveRDS() and readRDS(), respectively. Please note that the RDS data format is specific to R and it will be difficult to work with in other languages/environments.

For cross-platform support you might check out Google's ProtoBuf serialization mechanism as implemented in the RProtoBuf package. I have used this library for the export of R's Random Forest models:

library("RProtoBuf")
rf = randomForest(target ~ ., data = mydata)
con = file("rf.pb", open = "wb")
serialize_pb(rf, con)
close(con)
user1808924
  • 162
  • 2
  • Thanks! In the end, I ended up writing a custom export and then implementing a scorer on Scala -- but I didn't find a better answer than this one, and maybe I should have just gone with this approach. – Josh Marcus Oct 21 '14 at 18:13
  • I used this approach to build a PMML exporter for Random Forest models (my Java implementation is approximately 100x faster than R implementation). The internals of the `gbm` model data structure are very similar to `randomForest` model data structure, so it would be straightforward to build a PMML exporter for GBM models as well. – user1808924 Oct 21 '14 at 18:31
  • @user1808924 have you made any information about your exporter public, eg a Github repo? I'd be very interested in taking a look – Moderat Feb 29 '16 at 18:16
  • @Moderat You should check out https://github.com/jpmml/jpmml-r (Java library and command line app) and https://github.com/jpmml/r2pmml (its R wrapper). The ProtoBuf data format isn't so easy to work with, though. Have switched from ProtoBuf to RDS by now. – user1808924 Feb 29 '16 at 20:09