How to read PMML data from a text file and convert it to a model ?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

How to read PMML data from a text file and convert it to a model ?

Ashim Kapoor
Dear All,

I want to save the XML representation of a model using PMML. Then I want to
read the model and predict using the model and a new  dataset.

This is described in this blog post :
https://www.r-bloggers.com/predictive-modeling-using-r-and-the-openscoring-engine-a-pmml-approach/

I am able to save the PMML representation of the model. I am not able to
read this representation convert it into  a model.  How can I do that ?

Here is a MWE :

library(pmml)
mydata<- iris

# Creating a model

mymodel <- lm(Sepal.Length ~ Sepal.Width, data = mydata)
#Computing its pmml representation and storing it to a file
saveXML(pmml(mymodel),file = "myfile.xml")

testingReading <- fileToXMLNode("myfile.txt")

> testingReading
<PMML version="4.3" xmlns="http://www.dmg.org/PMML-4_3">
 <Header>
  <Application name="JPMML-R" version="1.2.20"/>
  <Timestamp>2017-11-15T10:37:29Z</Timestamp>
 </Header>
 <DataDictionary>
  <DataField name="Sepal.Length" optype="continuous" dataType="double"/>
  <DataField name="Sepal.Width" optype="continuous" dataType="double"/>
 </DataDictionary>
 <RegressionModel functionName="regression">
  <MiningSchema>
   <MiningField name="Sepal.Length" usageType="target"/>
   <MiningField name="Sepal.Width"/>
  </MiningSchema>
  <RegressionTable intercept="6.526222550894482">
   <NumericPredictor name="Sepal.Width" coefficient="-0.22336106112990006"/>
  </RegressionTable>
 </RegressionModel>
</PMML>
Warning messages:
1: In structure(x$children, class = "XMLNodeList") :
  Calling 'structure(NULL, *)' is deprecated, as NULL cannot have
attributes.
  Consider 'structure(list(), *)' instead.
2: In structure(x$children, class = "XMLNodeList") :
  Calling 'structure(NULL, *)' is deprecated, as NULL cannot have
attributes.
  Consider 'structure(list(), *)' instead.
3: In structure(x$children, class = "XMLNodeList") :
  Calling 'structure(NULL, *)' is deprecated, as NULL cannot have
attributes.
  Consider 'structure(list(), *)' instead.
4: In structure(x$children, class = "XMLNodeList") :
  Calling 'structure(NULL, *)' is deprecated, as NULL cannot have
attributes.
  Consider 'structure(list(), *)' instead.
5: In structure(x$children, class = "XMLNodeList") :
  Calling 'structure(NULL, *)' is deprecated, as NULL cannot have
attributes.
  Consider 'structure(list(), *)' instead.
6: In structure(x$children, class = "XMLNodeList") :
  Calling 'structure(NULL, *)' is deprecated, as NULL cannot have
attributes.
  Consider 'structure(list(), *)' instead.
>

Can someone show me how to extract the model from the variable
testingReading and predict using this model at the values of rnorm(100) ?

Best Regards,
Ashim

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.