Search code examples
pythonrpmml

How to convert .rda to .pmml and use it in Python


I've got myself a neural network model in .rda format that is already trained, and I'm not sure how to convert it to .pmml so that I can use it as a predictive engine in Python. Once this is done, which libraries should I install to allow the pmml file to be used in Python? Are there any special interactions I should be aware of?

-UPDATE- I installed r2pmml into my RStudio, and I was wondering if its possible to load a model from .rda format and instantly export it without having to train it. Can this be done?

-UPDATE 2- Managed to convert .Rda to .pmml successfully. I have a list of 0/1 vectors to use with the pmml file, (53,850 1's and 0's); how do I run the list through the predictive model in Python? One of the suggestions was to use Augustus.


Solution

  • The .rda file contains the model object in a R-specific serialization data format. You should be able to de-serialize it using the readRDS(rds_path) method, and then invoke the r2pmml(model, pmml_path) method.

    Training a model, and serializing it into a RDS file:

    library("randomForest")
    rf = randomForest(Species ~ ., data = iris)
    saveRDS(rf, "rf.rds")
    

    De-serializing the model from the RDS file, and exporting it into a PMML file:

    library("r2pmml")
    rf_clone = readRDS("rf.rds")
    r2pmml(rf_clone, "rf.pmml")