{"id":33112420,"url":"https://github.com/jpmml/r2pmml","last_synced_at":"2025-12-30T00:03:10.797Z","repository":{"id":27536290,"uuid":"31017625","full_name":"jpmml/r2pmml","owner":"jpmml","description":"R library for converting R models to PMML","archived":false,"fork":false,"pushed_at":"2025-12-15T19:41:35.000Z","size":66806,"stargazers_count":74,"open_issues_count":11,"forks_count":18,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-12-17T03:20:27.425Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jpmml.png","metadata":{"files":{"readme":"README.md","changelog":"NEWS.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-02-19T14:00:11.000Z","updated_at":"2025-12-15T19:41:39.000Z","dependencies_parsed_at":"2022-09-02T11:10:16.259Z","dependency_job_id":"ca7a267d-2ca0-4022-b40f-ab0710d70c66","html_url":"https://github.com/jpmml/r2pmml","commit_stats":{"total_commits":163,"total_committers":1,"mean_commits":163.0,"dds":0.0,"last_synced_commit":"7dcc8f34f7c108ceb852f3fc7702c8c1bab4ddf3"},"previous_names":[],"tags_count":74,"template":false,"template_full_name":null,"purl":"pkg:github/jpmml/r2pmml","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jpmml%2Fr2pmml","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jpmml%2Fr2pmml/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jpmml%2Fr2pmml/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jpmml%2Fr2pmml/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jpmml","download_url":"https://codeload.github.com/jpmml/r2pmml/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jpmml%2Fr2pmml/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28122314,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-12-29T02:00:07.021Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-11-15T01:00:44.746Z","updated_at":"2025-12-30T00:03:10.785Z","avatar_url":"https://github.com/jpmml.png","language":"R","readme":"R2PMML\n======\n\nR package for converting [R](https://www.r-project.org/) models to PMML\n\n# Features #\n\nThis library is a thin R wrapper around the [JPMML-R](https://github.com/jpmml/jpmml-r#features) library.\n\n# News and Updates #\n\nThe current version is **0.29.2** (5 January, 2025):\n\nSee the [NEWS.md](https://github.com/jpmml/r2pmml/blob/master/NEWS.md#0292) file.\n\n# Prerequisites #\n\n* Java 11 or newer. The Java executable must be available on system path.\n* R 3.3, 4.0 or newer.\n\n# Installation #\n\nInstalling a release version from CRAN:\n\n```R\ninstall.packages(\"r2pmml\")\n```\n\nAlternatively, installing the latest snapshot version from GitHub using the [`devtools`](https://cran.r-project.org/package=devtools) package:\n\n```R\nlibrary(\"devtools\")\n\ninstall_github(\"jpmml/r2pmml\")\n```\n\n# Usage #\n\n### Base functionality\n\nLoading the package:\n\n```R\nlibrary(\"r2pmml\")\n```\n\nTraining and exporting a simple `randomForest` model:\n\n```R\nlibrary(\"randomForest\")\nlibrary(\"r2pmml\")\n\ndata(iris)\n\n# Train a model using raw Iris dataset\niris.rf = randomForest(Species ~ ., data = iris, ntree = 7)\nprint(iris.rf)\n\n# Export the model to PMML\nr2pmml(iris.rf, \"iris_rf.pmml\")\n```\n\n### Data pre-processing\n\nThe `r2pmml` function takes an optional argument `preProcess`, which associates the model with data pre-processing transformations.\n\nTraining and exporting a more sophisticated `randomForest` model:\n\n```R\nlibrary(\"caret\")\nlibrary(\"randomForest\")\nlibrary(\"r2pmml\")\n\ndata(iris)\n\n# Create a preprocessor\niris.preProcess = preProcess(iris, method = c(\"range\"))\n\n# Use the preprocessor to transform raw Iris dataset to pre-processed Iris dataset\niris.transformed = predict(iris.preProcess, newdata = iris)\n\n# Train a model using pre-processed Iris dataset\niris.rf = randomForest(Species ~., data = iris.transformed, ntree = 7)\nprint(iris.rf)\n\n# Export the model to PMML.\n# Pass the preprocessor as the `preProcess` argument\nr2pmml(iris.rf, \"iris_rf.pmml\", preProcess = iris.preProcess)\n```\n\n### Model formulae\n\nAlternatively, it is possible to associate `lm`, `glm` and `randomForest` models with data pre-processing transformations using [model formulae](https://stat.ethz.ch/R-manual/R-devel/library/stats/html/formula.html).\n\nTraining and exporting a `glm` model:\n\n```R\nlibrary(\"plyr\")\nlibrary(\"r2pmml\")\n\n# Load and prepare the Auto-MPG dataset\nauto = read.table(\"http://archive.ics.uci.edu/ml/machine-learning-databases/auto-mpg/auto-mpg.data\", quote = \"\\\"\", header = FALSE, na.strings = \"?\", row.names = NULL, col.names = c(\"mpg\", \"cylinders\", \"displacement\", \"horsepower\", \"weight\", \"acceleration\", \"model_year\", \"origin\", \"car_name\"))\nauto$origin = as.factor(auto$origin)\nauto$car_name = NULL\nauto = na.omit(auto)\n\n# Train a model\nauto.glm = glm(mpg ~ (. - horsepower - weight - origin) ^ 2 + I(displacement / cylinders) + cut(horsepower, breaks = c(0, 50, 100, 150, 200, 250)) + I(log(weight)) + revalue(origin, replace = c(\"1\" = \"US\", \"2\" = \"Europe\", \"3\" = \"Japan\")), data = auto)\n\n# Export the model to PMML\nr2pmml(auto.glm, \"auto_glm.pmml\")\n```\n\n### Package `ranger`\n\nTraining and exporting a `ranger` model:\n\n```R\nlibrary(\"ranger\")\nlibrary(\"r2pmml\")\n\ndata(iris)\n\n# Train a model.\n# Keep the forest data structure by specifying `write.forest = TRUE`\niris.ranger = ranger(Species ~ ., data = iris, num.trees = 7, write.forest = TRUE)\nprint(iris.ranger)\n\n# Export the model to PMML.\n# Pass the training dataset as the `data` argument\nr2pmml(iris.ranger, \"iris_ranger.pmml\", data = iris)\n```\n\n### Package `xgboost`\n\nTraining and exporting an `xgb.Booster` model:\n\n```R\nlibrary(\"xgboost\")\nlibrary(\"r2pmml\")\n\ndata(iris)\n\niris_X = iris[, 1:4]\niris_y = as.integer(iris[, 5]) - 1\n\n# Generate R model matrix\niris.matrix = model.matrix(~ . - 1, data = iris_X)\n\n# Generate XGBoost DMatrix and feature map based on R model matrix\niris.DMatrix = xgb.DMatrix(iris.matrix, label = iris_y)\niris.fmap = as.fmap(iris.matrix)\n\n# Train a model\niris.xgb = xgboost(data = iris.DMatrix, missing = NULL, objective = \"multi:softmax\", num_class = 3, nrounds = 13)\n\n# Export the model to PMML.\n# Pass the feature map as the `fmap` argument.\n# Pass the name and category levels of the target field as `response_name` and `response_levels` arguments, respectively.\n# Pass the value of missing value as the `missing` argument\n# Pass the optimal number of trees as the `ntreelimit` argument (analogous to the `ntreelimit` argument of the `xgb::predict.xgb.Booster` function)\nr2pmml(iris.xgb, \"iris_xgb.pmml\", fmap = iris.fmap, response_name = \"Species\", response_levels = c(\"setosa\", \"versicolor\", \"virginica\"), missing = NULL, ntreelimit = 7, compact = TRUE)\n```\n\n### Advanced functionality\n\nTweaking JVM configuration:\n\n```R\nSys.setenv(JAVA_TOOL_OPTIONS = \"-Xms4G -Xmx8G\")\n\nr2pmml(iris.rf, \"iris_rf.pmml\")\n```\n\nEmploying a custom converter class:\n\n```R\nr2pmml(iris.rf, \"iris_rf.pmml\", converter = \"com.mycompany.MyRandomForestConverter\", converter_classpath = \"/path/to/myconverter-1.0-SNAPSHOT.jar\")\n```\n\n# De-installation #\n\nRemoving the package:\n\n```R\nremove.packages(\"r2pmml\")\n```\n\n# Documentation #\n\nUp-to-date:\n\n* [Converting logistic regression models to PMML documents](https://openscoring.io/blog/2020/01/19/converting_logistic_regression_pmml/#r)\n* [Deploying R language models on Apache Spark ML](https://openscoring.io/blog/2019/02/09/deploying_rlang_model_sparkml/)\n\nSlightly outdated:\n\n* [Converting R to PMML](https://www.slideshare.net/VilluRuusmann/converting-r-to-pmml-82182483)\n\n# License #\n\nR2PMML is licensed under the terms and conditions of the [GNU Affero General Public License, Version 3.0](https://www.gnu.org/licenses/agpl-3.0.html).\n\nIf you would like to use R2PMML in a proprietary software project, then it is possible to enter into a licensing agreement which makes R2PMML available under the terms and conditions of the [BSD 3-Clause License](https://opensource.org/license/bsd-3-clause) instead.\n\n# Additional information #\n\nR2PMML is developed and maintained by Openscoring Ltd, Estonia.\n\nInterested in using [Java PMML API](https://github.com/jpmml) software in your company? Please contact [info@openscoring.io](mailto:info@openscoring.io)","funding_links":[],"categories":["Model serialisation formats","Main Contents"],"sub_categories":["Model Standard Formats for interoperability"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjpmml%2Fr2pmml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjpmml%2Fr2pmml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjpmml%2Fr2pmml/lists"}