imbs-hl / ranger

A Fast Implementation of Random Forests
http://imbs-hl.github.io/ranger/
776 stars 193 forks source link

Save R model to use in CPP application #549

Open natineo opened 3 years ago

natineo commented 3 years ago

Hi, First of all thanks for the great work!

I am using the R package for data processing and analysis. I need to import a forest computed with R into a CPP application, which already loads some ".forest" files with the ranger initForest() method, to enable predictions in the CPP application with the predict() method. Unfortunately, I don't know how to export my R model into such a loadable file.

mnwright commented 3 years ago

That's currently not possible implemented.

The structure of the .forest files is quite simple, see here https://github.com/imbs-hl/ranger/blob/e8b05f47892bb4968c4e6057f68b35bcd0b52225/src/Forest.cpp#L402 and e.g. here https://github.com/imbs-hl/ranger/blob/e8b05f47892bb4968c4e6057f68b35bcd0b52225/src/ForestClassification.cpp#L271.

But if possible I would prefer to re-train the models.

natineo commented 3 years ago

Thanks for the references in the cpp code. I don't know if this could be a popular feature but in my case an easy integration of R-trained models (or possibly Python #523) into cpp applications would be a strong argument in favor of your library, compared to other solutions.