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')