Can PMML models be read in R?
Asked Answered
C

5

12

I have a PMML file which I am trying to import/read in R to do some analysis based on it. I couldn't find a suitable function to read the model, although I found a package that is related to PMML. Is there is a simple way to read this type of file into R?

Thanks,

Conspicuous answered 31/10, 2013 at 23:37 Comment(3)
as far as I can tell the answer to this question is still "it depends what kind of model you're trying to read, but there is no general pre-packaged solution". The problem is that someone would have to write the XML-to-R object mapping function, which has at present only been done for subclasses (trees; partykit; association rules, arules). It would be to hard to write that particular XML -> GLM rule, but would that actually solve your problem?Flatulent
@BenBolker Yes -- I think an answer along the lines of "here are all the cases where you can use a pre-packaged solution, and then here's an example of how to do the object mapping where no pre-packaged solution exists" would be much better than the piecemeal answers here.Lapointe
You really need to switch the checked solution to the correct answer that you awarded the bounty to, otherwise readers incorrectly think that you can import PMML from other systems when you can not.Tantalous
E
11

Unfortunately, it is not possible to import a model in PMML format in order to predict the classes of some instances using R.

The pmml package only allow you to train a model in R and then export it.

Educationist answered 2/4, 2014 at 10:7 Comment(1)
Yep, though the Rdocumentation link Dirk Eddelbuettel seems to allow you to read a PMML file - rdocumentation.org/packages/arules/functions/pmmlHarbert
O
6

There is now a way to read PMML objects into R, using the great "partykit" package.

I tried it out with a node from SPSS and it works.

Here is the link to the vignette explaining how: https://cran.r-project.org/web/packages/partykit/vignettes/constparty.pdf

Oppression answered 31/8, 2015 at 23:22 Comment(2)
But does this work for other types of models (not trees, but linear regression for example)?Lapointe
@Lapointe I haven't tried it, but being an xml object all the same it should work as well ...Oppression
B
2

There is currently no way to import a model via PMML unless the model was created using the arules package. The authors of that package have provided a way to import/export arules models

http://cran.r-project.org/web/packages/arules/index.html

Brutalize answered 27/1, 2015 at 0:28 Comment(0)
J
2

Although it's a long time ago, I still want to share that you can use the "reticulate" to call the python pypmml package to implement your ideas in R, and in order to be more friendly and make the prediction look more like the predict function in R, I will It is encapsulated, the address of the package is here "https://github.com/xianglinZ/RLoadPmml"

Jaborandi answered 10/8, 2021 at 9:42 Comment(0)
T
0

Yes there is even a pmml package.

And see the Rdocumentation.org result for searching for pmml

Thermogenesis answered 31/10, 2013 at 23:39 Comment(3)
I don't think there is an IMPORT option in the R PMML package.Cryolite
The provided link only reads PMML models created by the arules package, so it's not applicable for all PMML models...Salute
but what is the point of being able to read pmml files generated only from that tool. After all pmml is a standard. and the whole point is being interoperableSommer

© 2022 - 2024 — McMap. All rights reserved.