addOutputField: Add Output nodes to a PMML object.

Description Usage Arguments Details Value Author(s) Examples

View source: R/addOutputField.R

Description

Add Output nodes to a PMML object.

Usage

1
2
3
addOutputField(xmlmodel = NULL, outputNodes = NULL, at = "End",
  xformText = NULL, nodeName = NULL, attributes = NULL, whichOutput = 1,
  namespace = "4_3")

Arguments

xmlmodel

The PMML model to which the OutputField elements are to be added

outputNodes

The Output nodes to be added. These may be created using the 'makeOutputNodes' helper function

at

Given an Output element, the 1 based index after which the given Output child element should be inserted at

xformText

Post-processing information to be included in the OutputField element. This expression will be processed by the functionToPMML function

nodeName

The name of the element to be added

attributes

The attributes to be added

whichOutput

The index of the Output element

namespace

The namespace of the PMML model

Details

This function is meant to add any post-processing information to an existing model via the OutputField element. One can also use this to tell the PMML model to output other values not automatically added to the model output. The first method is to use the 'makeOutputNodes' helper function to make a list of output elements to be added. 'whichOutput' lets the function know which of the Output elements we want to work with; there may be more than one in a multiple model file. One can then add those elements there, at the desired index given by the 'at' parameter; the elements are inserted after the OutputField element at the 'at' index. In other words, find the 'whichOutput' Output element, add the 'outputNodes' child elements (which should be OutputField nodes) at the 'at' position in the child nodes. This function can also be used with the 'nodeName' and 'attributes' to add the list of attributes to an OutputField element with name 'nodeName' element using the 'xmlmodel', 'outputNodes' and 'at' parameters. Finally, one can use this to add the transformation expression given by the 'xformText' parameter to the node with name 'nodeName'. The string given via 'xformText' is converted to an XML expression similarly to the functionToPMML function. In other words, find the OutputField node with tha name 'nodeName' and add the list of attributes given with 'attributes' and also, add the child transformations given in the 'xformText' parameter.

Value

Output node with the OutputField elements inserted.

Author(s)

Tridivesh Jena

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# Load the standard iris dataset
data(iris)

# Create a linear model and convert it to PMML
mod <- lm(Sepal.Length~.,iris)
pmod <- pmml(mod)

# Create additional output nodes
onodes0<-makeOutputNodes(name=list("OutputField","OutputField"),
                         attributes=list(list(name="dbl",
                         optype="continuous"),NULL),
                         expression=list("ln(x)","ln(x/(1-x))"))
onodes2<-makeOutputNodes(name=list("OutputField","OutputField"),
                         attributes=list(list(name="F1",
                         dataType="double",optype="continuous"),
                         list(name="F2")))

# Create new pmml objects with the output nodes appended
addOutputField(xmlmodel=pmod, outputNodes=onodes2, at="End", 
               xformText=NULL, nodeName=NULL, attributes=NULL,
               whichOutput=1)
pmod2<-addOutputField(xmlmodel=pmod, outputNodes=onodes0, at="End", 
                       xformText=NULL, nodeName=NULL, 
                       attributes=NULL,whichOutput=1)

# Create nodes with attributes and transformations
addOutputField(xmlmodel=pmod2, outputNodes=onodes2,at=2)
addOutputField(xmlmodel=pmod2, xformText=list("exp(x) && !x"), 
               nodeName="Predicted_Sepal.Length")

att <- list(datype="dbl",optpe="dsc")
addOutputField(xmlmodel=pmod2, nodeName="Predicted_Sepal.Length", 
               attributes=att)

Example output

Loading required package: XML
<?xml version="1.0"?>
<PMML xmlns="http://www.dmg.org/PMML-4_3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="4.3" xsi:schemaLocation="http://www.dmg.org/PMML-4_3 http://www.dmg.org/pmml/v4-3/pmml-4-3.xsd">
  <Header copyright="Copyright (c) 2018 unknown" description="Linear Regression Model">
    <Extension name="user" value="unknown" extender="Rattle/PMML"/>
    <Application name="Rattle/PMML" version="1.4"/>
    <Timestamp>2018-03-21 06:56:39</Timestamp>
  </Header>
  <DataDictionary numberOfFields="5">
    <DataField name="Sepal.Length" optype="continuous" dataType="double"/>
    <DataField name="Sepal.Width" optype="continuous" dataType="double"/>
    <DataField name="Petal.Length" optype="continuous" dataType="double"/>
    <DataField name="Petal.Width" optype="continuous" dataType="double"/>
    <DataField name="Species" optype="categorical" dataType="string">
      <Value value="setosa"/>
      <Value value="versicolor"/>
      <Value value="virginica"/>
    </DataField>
  </DataDictionary>
  <RegressionModel modelName="Linear_Regression_Model" functionName="regression" algorithmName="least squares">
    <MiningSchema>
      <MiningField name="Sepal.Length" usageType="predicted"/>
      <MiningField name="Sepal.Width" usageType="active"/>
      <MiningField name="Petal.Length" usageType="active"/>
      <MiningField name="Petal.Width" usageType="active"/>
      <MiningField name="Species" usageType="active"/>
    </MiningSchema>
    <Output>
      <OutputField name="Predicted_Sepal.Length" feature="predictedValue"/>
      <OutputField name="F1" dataType="double" optype="continuous"/>
      <OutputField name="F2"/>
    </Output>
    <RegressionTable intercept="2.17126629215507">
      <NumericPredictor name="Sepal.Width" exponent="1" coefficient="0.495888938388552"/>
      <NumericPredictor name="Petal.Length" exponent="1" coefficient="0.829243912234806"/>
      <NumericPredictor name="Petal.Width" exponent="1" coefficient="-0.315155173326474"/>
      <CategoricalPredictor name="Species" value="setosa" coefficient="0"/>
      <CategoricalPredictor name="Species" value="versicolor" coefficient="-0.723561957780728"/>
      <CategoricalPredictor name="Species" value="virginica" coefficient="-1.02349781449083"/>
    </RegressionTable>
  </RegressionModel>
</PMML>
 
Warning message:
In addOutputField(xmlmodel = pmod, outputNodes = onodes2, at = "End",  :
  OutputField given, childNode and attributes ignored.
Warning message:
In addOutputField(xmlmodel = pmod, outputNodes = onodes0, at = "End",  :
  OutputField given, childNode and attributes ignored.
<?xml version="1.0"?>
<PMML xmlns="http://www.dmg.org/PMML-4_3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="4.3" xsi:schemaLocation="http://www.dmg.org/PMML-4_3 http://www.dmg.org/pmml/v4-3/pmml-4-3.xsd">
  <Header copyright="Copyright (c) 2018 unknown" description="Linear Regression Model">
    <Extension name="user" value="unknown" extender="Rattle/PMML"/>
    <Application name="Rattle/PMML" version="1.4"/>
    <Timestamp>2018-03-21 06:56:39</Timestamp>
  </Header>
  <DataDictionary numberOfFields="5">
    <DataField name="Sepal.Length" optype="continuous" dataType="double"/>
    <DataField name="Sepal.Width" optype="continuous" dataType="double"/>
    <DataField name="Petal.Length" optype="continuous" dataType="double"/>
    <DataField name="Petal.Width" optype="continuous" dataType="double"/>
    <DataField name="Species" optype="categorical" dataType="string">
      <Value value="setosa"/>
      <Value value="versicolor"/>
      <Value value="virginica"/>
    </DataField>
  </DataDictionary>
  <RegressionModel modelName="Linear_Regression_Model" functionName="regression" algorithmName="least squares">
    <MiningSchema>
      <MiningField name="Sepal.Length" usageType="predicted"/>
      <MiningField name="Sepal.Width" usageType="active"/>
      <MiningField name="Petal.Length" usageType="active"/>
      <MiningField name="Petal.Width" usageType="active"/>
      <MiningField name="Species" usageType="active"/>
    </MiningSchema>
    <Output>
      <OutputField name="Predicted_Sepal.Length" feature="predictedValue"/>
      <OutputField name="dbl" optype="continuous">
        <Apply function="ln">
          <FieldRef field="x"/>
        </Apply>
      </OutputField>
      <OutputField name="F1" dataType="double" optype="continuous"/>
      <OutputField name="F2"/>
      <OutputField>
        <Apply function="ln">
          <Apply function="/">
            <FieldRef field="x"/>
            <Apply function="-">
              <Constant dataType="double">1</Constant>
              <FieldRef field="x"/>
            </Apply>
          </Apply>
        </Apply>
      </OutputField>
    </Output>
    <RegressionTable intercept="2.17126629215507">
      <NumericPredictor name="Sepal.Width" exponent="1" coefficient="0.495888938388552"/>
      <NumericPredictor name="Petal.Length" exponent="1" coefficient="0.829243912234806"/>
      <NumericPredictor name="Petal.Width" exponent="1" coefficient="-0.315155173326474"/>
      <CategoricalPredictor name="Species" value="setosa" coefficient="0"/>
      <CategoricalPredictor name="Species" value="versicolor" coefficient="-0.723561957780728"/>
      <CategoricalPredictor name="Species" value="virginica" coefficient="-1.02349781449083"/>
    </RegressionTable>
  </RegressionModel>
</PMML>
 
Warning message:
In addOutputField(xmlmodel = pmod2, outputNodes = onodes2, at = 2) :
  OutputField given, childNode and attributes ignored.
<?xml version="1.0"?>
<PMML xmlns="http://www.dmg.org/PMML-4_3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="4.3" xsi:schemaLocation="http://www.dmg.org/PMML-4_3 http://www.dmg.org/pmml/v4-3/pmml-4-3.xsd">
  <Header copyright="Copyright (c) 2018 unknown" description="Linear Regression Model">
    <Extension name="user" value="unknown" extender="Rattle/PMML"/>
    <Application name="Rattle/PMML" version="1.4"/>
    <Timestamp>2018-03-21 06:56:39</Timestamp>
  </Header>
  <DataDictionary numberOfFields="5">
    <DataField name="Sepal.Length" optype="continuous" dataType="double"/>
    <DataField name="Sepal.Width" optype="continuous" dataType="double"/>
    <DataField name="Petal.Length" optype="continuous" dataType="double"/>
    <DataField name="Petal.Width" optype="continuous" dataType="double"/>
    <DataField name="Species" optype="categorical" dataType="string">
      <Value value="setosa"/>
      <Value value="versicolor"/>
      <Value value="virginica"/>
    </DataField>
  </DataDictionary>
  <RegressionModel modelName="Linear_Regression_Model" functionName="regression" algorithmName="least squares">
    <MiningSchema>
      <MiningField name="Sepal.Length" usageType="predicted"/>
      <MiningField name="Sepal.Width" usageType="active"/>
      <MiningField name="Petal.Length" usageType="active"/>
      <MiningField name="Petal.Width" usageType="active"/>
      <MiningField name="Species" usageType="active"/>
    </MiningSchema>
    <Output>
      <OutputField name="Predicted_Sepal.Length" feature="predictedValue">
        <Apply function="and">
          <Apply function="exp">
            <FieldRef field="x"/>
          </Apply>
          <Apply function="not">
            <FieldRef field="x"/>
          </Apply>
        </Apply>
      </OutputField>
      <OutputField name="dbl" optype="continuous">
        <Apply function="ln">
          <FieldRef field="x"/>
        </Apply>
      </OutputField>
      <OutputField>
        <Apply function="ln">
          <Apply function="/">
            <FieldRef field="x"/>
            <Apply function="-">
              <Constant dataType="double">1</Constant>
              <FieldRef field="x"/>
            </Apply>
          </Apply>
        </Apply>
      </OutputField>
    </Output>
    <RegressionTable intercept="2.17126629215507">
      <NumericPredictor name="Sepal.Width" exponent="1" coefficient="0.495888938388552"/>
      <NumericPredictor name="Petal.Length" exponent="1" coefficient="0.829243912234806"/>
      <NumericPredictor name="Petal.Width" exponent="1" coefficient="-0.315155173326474"/>
      <CategoricalPredictor name="Species" value="setosa" coefficient="0"/>
      <CategoricalPredictor name="Species" value="versicolor" coefficient="-0.723561957780728"/>
      <CategoricalPredictor name="Species" value="virginica" coefficient="-1.02349781449083"/>
    </RegressionTable>
  </RegressionModel>
</PMML>
 
Warning message:
In addOutputField(xmlmodel = pmod2, xformText = list("exp(x) && !x"),  :
  childNode will be added. outputNode and attributes will be ignored.
<?xml version="1.0"?>
<PMML xmlns="http://www.dmg.org/PMML-4_3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="4.3" xsi:schemaLocation="http://www.dmg.org/PMML-4_3 http://www.dmg.org/pmml/v4-3/pmml-4-3.xsd">
  <Header copyright="Copyright (c) 2018 unknown" description="Linear Regression Model">
    <Extension name="user" value="unknown" extender="Rattle/PMML"/>
    <Application name="Rattle/PMML" version="1.4"/>
    <Timestamp>2018-03-21 06:56:39</Timestamp>
  </Header>
  <DataDictionary numberOfFields="5">
    <DataField name="Sepal.Length" optype="continuous" dataType="double"/>
    <DataField name="Sepal.Width" optype="continuous" dataType="double"/>
    <DataField name="Petal.Length" optype="continuous" dataType="double"/>
    <DataField name="Petal.Width" optype="continuous" dataType="double"/>
    <DataField name="Species" optype="categorical" dataType="string">
      <Value value="setosa"/>
      <Value value="versicolor"/>
      <Value value="virginica"/>
    </DataField>
  </DataDictionary>
  <RegressionModel modelName="Linear_Regression_Model" functionName="regression" algorithmName="least squares">
    <MiningSchema>
      <MiningField name="Sepal.Length" usageType="predicted"/>
      <MiningField name="Sepal.Width" usageType="active"/>
      <MiningField name="Petal.Length" usageType="active"/>
      <MiningField name="Petal.Width" usageType="active"/>
      <MiningField name="Species" usageType="active"/>
    </MiningSchema>
    <Output>
      <OutputField name="Predicted_Sepal.Length" feature="predictedValue" datype="dbl" optpe="dsc"/>
      <OutputField name="dbl" optype="continuous">
        <Apply function="ln">
          <FieldRef field="x"/>
        </Apply>
      </OutputField>
      <OutputField>
        <Apply function="ln">
          <Apply function="/">
            <FieldRef field="x"/>
            <Apply function="-">
              <Constant dataType="double">1</Constant>
              <FieldRef field="x"/>
            </Apply>
          </Apply>
        </Apply>
      </OutputField>
    </Output>
    <RegressionTable intercept="2.17126629215507">
      <NumericPredictor name="Sepal.Width" exponent="1" coefficient="0.495888938388552"/>
      <NumericPredictor name="Petal.Length" exponent="1" coefficient="0.829243912234806"/>
      <NumericPredictor name="Petal.Width" exponent="1" coefficient="-0.315155173326474"/>
      <CategoricalPredictor name="Species" value="setosa" coefficient="0"/>
      <CategoricalPredictor name="Species" value="versicolor" coefficient="-0.723561957780728"/>
      <CategoricalPredictor name="Species" value="virginica" coefficient="-1.02349781449083"/>
    </RegressionTable>
  </RegressionModel>
</PMML>
 
Warning message:
In addOutputField(xmlmodel = pmod2, nodeName = "Predicted_Sepal.Length",  :
  attributes given, outputNode and childNode will be ignored

pmml documentation built on Jan. 9, 2018, 1:06 a.m.

Related to addOutputField in pmml...