Learn R Programming

pmml (version 1.2.21)

pmml.rpart: Generate PMML for an rpart object

Description

Generate the PMML (Predictive Model Markup Language) representation of an rpart object (classification tree). The rpart object (currently expected to be a classification tree) is converted into a PMML representation. The PMML can then be imported into other systems that accept PMML.

Usage

## S3 method for class 'rpart':
pmml(model, model.name="RPart_Model", app.name="Rattle/PMML",
     description="RPart Decision Tree Model", copyright=NULL,
transforms=NULL, dataset=NULL, \dots)

Arguments

model
an rpart object.
model.name
a name to give to the model in the PMML.
app.name
the name of the application that generated the PMML.
description
a descriptive text for the header of the PMML.
copyright
the copyright notice for the model.
transforms
a coded list of transforms performed.
dataset
the orginal training dataset, if available.
...
further arguments passed to or from other methods.

Details

The generated PMML can be imported into any PMML consuming application, such as Teradata Warehouse Miner and DB2. Generally, these applications convert the PMML into SQL for execution across a database.

Teradata, for example, generates a single SELECT statement to implement a decision tree. In the Examples section below, we use the rpart example to build a model stored in the variable fit. A segment of the PMML for this model is:

The resulting SQL from Teradata includes:

CREATE TABLE "MyScores" AS ( SELECT "UserID", (CASE WHEN _node = 0 THEN 'absent' WHEN _node = 1 THEN 'absent' WHEN _node = 2 THEN 'absent' WHEN _node = 3 THEN 'present' WHEN _node = 4 THEN 'present' ELSE NULL END) (VARCHAR(8)) AS "Kyphosis" FROM (SELECT "UserID", (CASE WHEN ("Start" >= 8.5) AND ("Start" >= 14.5) THEN 0 WHEN ("Start" >= 8.5) AND ("Start" < 14.5) AND ("Age" < 55) THEN 1 WHEN ("Start" >= 8.5) AND ("Start" < 14.5) AND ("Age" >= 55) AND ("Age" >= 111) THEN 2 WHEN ("Start" >= 8.5) AND ("Start" < 14.5) AND ("Age" >= 55) AND ("Age" < 111) THEN 3 WHEN ("Start" < 8.5) THEN 4 ELSE -1 END) AS _node FROM "MyData" WHERE _node IS NOT NULL) A WHERE "Kyphosis" IS NOT NULL) WITH DATA UNIQUE PRIMARY INDEX ("UserID");

References

Package home page: http://rattle.togaware.com

PMML home page: http://www.dmg.org

Zementis' useful PMML convert: http://www.zementis.com/pmml_converters.htm

See Also

pmml.

Examples

Run this code
library(rpart)
(iris.rpart <- rpart(Species ~ ., data=iris))
pmml(iris.rpart)

Run the code above in your browser using DataLab