Learn R Programming

R package pmml - Generate PMML for Various Models

Overview

Export various machine learning and statistical models to PMML and generate data transformations in PMML format. Many commercial and open data mining platforms support PMML. This includes IBM SPSS Modeler, KNIME, Microsoft SQL Server, and SAS Enterprise Miner (see complete list).

Supported models include:

  • Anomaly Detection
  • Association Rules
  • Clustering
  • K Nearest Neighbors
  • Linear Models
  • Naive Bayes Classifiers
  • Neural Networks
  • Support Vector Machines
  • Time Series
  • Tree-based Models and Ensembles
  • Survival analysis models

Supported packages: ada, amap, arules, e1071, forecast, gbm, glmnet, isofor, kernlab, neighbr, stats, nnet, randomForest, rpart, survival, xgboost

For a description of the supported packages, see the vignette: Supported Packages and Additional Functions.

Related Packages

The Java library JMML provides an R interface to create PMML models called r2pmml available from CRAN and an evaluator jpmml which can be installed from Github.

Installation

Stable CRAN version: Install from within R with

install.packages("pmml")

Current development version: Install from r-universe.

install.packages("pmml",
    repos = c("https://mhahsler.r-universe.dev",
              "https://cloud.r-project.org/"))

Example

library(pmml)

# Build an lm model
iris_lm <- lm(Sepal.Length ~ ., data = iris)

# Convert to pmml
iris_lm_pmml <- pmml(iris_lm)

# The PMML model
iris_lm_pmml
#> <PMML version="4.4.1" xmlns="http://www.dmg.org/PMML-4_4" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.dmg.org/PMML-4_4 http://www.dmg.org/pmml/v4-4/pmml-4-4.xsd">
#>  <Header copyright="Copyright (c) 2026 mhahsler" description="Linear Regression Model">
#>   <Extension name="user" value="mhahsler" extender="R PMML Generator - Package pmml"/>
#>   <Application name="R PMML Generator - Package pmml" version="2.6.0.1"/>
#>   <Timestamp>2026-03-26 08:51:55.42062</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="lm_Model" functionName="regression" algorithmName="least squares">
#>   <MiningSchema>
#>    <MiningField name="Sepal.Length" usageType="predicted" invalidValueTreatment="returnInvalid"/>
#>    <MiningField name="Sepal.Width" usageType="active" invalidValueTreatment="returnInvalid"/>
#>    <MiningField name="Petal.Length" usageType="active" invalidValueTreatment="returnInvalid"/>
#>    <MiningField name="Petal.Width" usageType="active" invalidValueTreatment="returnInvalid"/>
#>    <MiningField name="Species" usageType="active" invalidValueTreatment="returnInvalid"/>
#>   </MiningSchema>
#>   <Output>
#>    <OutputField name="Predicted_Sepal.Length" optype="continuous" dataType="double" feature="predictedValue"/>
#>   </Output>
#>   <RegressionTable intercept="2.17126629215507">
#>    <NumericPredictor name="Sepal.Width" exponent="1" coefficient="0.495888938388551"/>
#>    <NumericPredictor name="Petal.Length" exponent="1" coefficient="0.829243912234806"/>
#>    <NumericPredictor name="Petal.Width" exponent="1" coefficient="-0.315155173326473"/>
#>    <CategoricalPredictor name="Species" value="setosa" coefficient="0"/>
#>    <CategoricalPredictor name="Species" value="versicolor" coefficient="-0.72356195778073"/>
#>    <CategoricalPredictor name="Species" value="virginica" coefficient="-1.02349781449083"/>
#>   </RegressionTable>
#>  </RegressionModel>
#> </PMML>

# Write to file: save_pmml(iris_lm_pmml,'iris_lm.pmml')

References

Copy Link

Version

Install

install.packages('pmml')

Monthly Downloads

420

Version

2.6.0

License

GPL-3 | file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Michael Hahsler

Last Published

March 26th, 2026

Functions in pmml (2.6.0)

make_values

Create Values element, most likely to add to a DataDictionary element.
pmml.hclust

Generate the PMML representation for a hclust object from the package amap.
pmml.nnet

Generate the PMML representation for a nnet object from package nnet.
pmml.randomForest

Generate the PMML representation for a randomForest object from the package randomForest.
pmml.neighbr

Generate PMML for a neighbr object from the neighbr package.
pmml.naiveBayes

Generate the PMML representation for a naiveBayes object from the package e1071.
pmml.kmeans

Generate the PMML representation for a kmeans object from the package stats.
pmml.rpart

Generate the PMML representation for an rpart object from the package rpart.
pmml.rules

Generate the PMML representation for a rules or an itemset object from package arules.
pmml.ksvm

Generate the PMML representation for a ksvm object from the package kernlab.
rename_wrap_var

Rename a variable in the xform_wrap transform object.
xform_map

Implement a map between discrete values in accordance with the PMML element MapValues.
save_pmml

Save a pmml object as an external PMML file.
pmml.lm

Generate the PMML representation for an lm object from the package stats.
pmml.multinom

Generate the PMML representation for a multinom object from package nnet.
xform_function

Add a function transformation to a xform_wrap object.
xform_discretize

Discretize a continuous variable as indicated by interval mappings in accordance with the PMML element Discretize.
pmml.iForest

Generate PMML for an iForest object from the isofor package.
xform_z_score

Perform a z-score normalization on continuous values in accordance with the PMML element NormContinuous.
pmml.xgb.Booster

Generate PMML for a xgb.Booster object from the package xgboost.
xform_wrap

Wrap data in a data transformations object.
pmml.svm

Generate the PMML representation of an svm object from the e1071 package.
xform_norm_discrete

Normalize discrete values in accordance with the PMML element NormDiscrete.
xform_min_max

Normalize continuous values in accordance with the PMML element NormContinuous.
function_to_pmml

Convert an R expression to PMML.
houseVotes84

Modified 1984 United States Congressional Voting Records Database
make_intervals

Create Interval elements, most likely to add to a DataDictionary element.
add_output_field

Add Output nodes to a PMML object.
pmml

Generate the PMML representation for R objects.
pmml.gbm

Generate the PMML representation for a gbm object from the package gbm.
pmml.glm

Generate the PMML representation for a glm object from the package stats.
pmml.coxph

Generate the PMML representation for a coxph object from the package survival.
pmml.cv.glmnet

Generate the PMML representation for a cv.glmnet object from the package glmnet.
pmml.ada

Generate the PMML representation for an ada object from the package ada.
add_mining_field_attributes

Add attribute values to an existing MiningField element in a given PMML file.
file_to_xml_node

Read in a file and parse it into an object of type XMLNode.
make_output_nodes

Add Output nodes to a PMML object.
add_data_field_attributes

Add attribute values to an existing DataField element in a given PMML file
add_attributes

Add attribute values to an existing element in a given PMML file.
pmml-package

pmml: Generate PMML for R Models
add_data_field_children

Add 'Interval' and 'Value' child elements to a given DataField element in a given PMML file.
audit

Audit: artificially constructed dataset
pmml.ARIMA

Generate PMML for an ARIMA object the forecast package.