View on GitHub

r-pmml

Generate PMML for various machine learning and statistical models.

R package pmml - Generate PMML for Various Models

Package on
CRAN CRAN RStudio mirror
downloads License Anaconda.org r-universe
status StackOverflow

This is the official home for the R package pmml (starting with version pmml_2.6.0). Previous versions can be found at here.

Overview

The pmml package lets you train machine learning and statistical models in R and then export them using the Predictive Model Markup Language (PMML). Many commercial and open data mining platforms support PMML to exchange models. This includes Python’s scikit learn, Java, IBM SPSS Modeler, KNIME, Microsoft SQL Server, and SAS Enterprise Miner (see complete list).

Supported models include:

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.

Java

The Java library JMML can be used to read and execute models stored in PMML format. An R interface to the library to create PMML models is called r2pmml and available from CRAN. An R interface for the evaluator, called jpmml, can be installed from Github.

Python

sklearn-pmml-model can import models trained on R into Python’s scikit-learn framework.

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-28 18:37:00.698143</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