{"id":13467151,"url":"https://github.com/jpmml/jpmml-xgboost","last_synced_at":"2025-12-24T10:29:04.058Z","repository":{"id":47728503,"uuid":"52436167","full_name":"jpmml/jpmml-xgboost","owner":"jpmml","description":"Java library and command-line application for converting XGBoost models to PMML","archived":false,"fork":false,"pushed_at":"2025-02-05T17:17:10.000Z","size":16722,"stargazers_count":129,"open_issues_count":2,"forks_count":44,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-02-05T18:32:10.116Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","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":"2016-02-24T11:07:32.000Z","updated_at":"2025-02-05T17:17:14.000Z","dependencies_parsed_at":"2023-12-10T20:24:20.147Z","dependency_job_id":"49269c35-a5db-4732-bfd6-91f7208d2379","html_url":"https://github.com/jpmml/jpmml-xgboost","commit_stats":null,"previous_names":[],"tags_count":70,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jpmml%2Fjpmml-xgboost","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jpmml%2Fjpmml-xgboost/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jpmml%2Fjpmml-xgboost/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jpmml%2Fjpmml-xgboost/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jpmml","download_url":"https://codeload.github.com/jpmml/jpmml-xgboost/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245571651,"owners_count":20637372,"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","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":"2024-07-31T15:00:53.596Z","updated_at":"2025-12-24T10:29:04.044Z","avatar_url":"https://github.com/jpmml.png","language":"Java","funding_links":[],"categories":["Java","人工智能"],"sub_categories":["机器学习"],"readme":"JPMML-XGBoost [![Build Status](https://github.com/jpmml/jpmml-xgboost/workflows/maven/badge.svg)](https://github.com/jpmml/jpmml-xgboost/actions?query=workflow%3A%22maven%22)\n=============\n\nJava library and command-line application for converting [XGBoost](https://github.com/dmlc/xgboost) models to PMML.\n\n# Features #\n\nSupports all XGBoost versions 0.4 through 3.1.\n\n* Functionality:\n  * Model data formats:\n    * Binary (XGBoost 0.4 and newer)\n    * JSON (XGBoost 1.0 and newer)\n    * Universal Binary JSON (UBJSON) (XGBoost 1.6 and newer)\n  * Gradient boosters:\n    * GBTree\n    * DART\n  * Target cardinality:\n    * Single-target\n    * One-Model-Per-Target (OMPT)-style Multi-target\n  * Feature maps\n  * Split types:\n    * Numeric (XGBoost 0.4 and newer)\n    * Categorical, One-Hot-Encoding (OHE)-based (XGBoost 1.3 and newer)\n    * Categorical, Set-based (XGBoost 1.6 and newer)\n    * Missing values (XGBoost 0.4 and newer)\n  * Objective functions:\n    * Regression\n    * Binary- and multi-class classification\n    * Ranking\n    * Survival Analysis\n* Conversion options:\n  * Truncation (`ntree_limit` aka `iteration_range` parameters)\n  * Elimination of empty and constant trees\n  * Tree rearrangements:\n    * Compaction and flattening (reshaping deep binary trees into shallow multi-way trees)\n    * Pruning\n* Production quality:\n  * Complete test coverage.\n  * Fully compliant with [JPMML-Evaluator](https://github.com/jpmml/jpmml-evaluator) and [JPMML-Transpiler](https://github.com/jpmml/jpmml-transpiler) libraries\n\n# News and Updates #\n\nSee the [NEWS.md](https://github.com/jpmml/jpmml-xgboost/blob/master/NEWS.md#182) file.\n\n# Prerequisites #\n\n* Java 11 or newer.\n\n# Installation #\n\nEnter the project root directory and build using [Apache Maven](https://maven.apache.org/):\n```\nmvn clean install\n```\n\nThe build produces a library JAR file `pmml-xgboost/target/pmml-xgboost-1.9-SNAPSHOT.jar`, and an executable uber-JAR file `pmml-xgboost-example/target/pmml-xgboost-example-executable-1.9-SNAPSHOT.jar`.\n\n# Usage #\n\nA typical workflow can be summarized as follows:\n\n1. Use XGBoost to train a model.\n2. Save the model and the associated feature map to files in a local filesystem.\n3. Use the JPMML-XGBoost command-line converter application to turn those two files to a PMML file.\n\n### The XGBoost side of operations\n\nTraining a binary classification model using the [Audit.csv](https://github.com/jpmml/jpmml-xgboost/blob/master/pmml-xgboost/src/test/resources/csv/Audit.csv) dataset.\n\n#### R language\n\n```R\nlibrary(\"r2pmml\")\nlibrary(\"xgboost\")\n\ndf = read.csv(\"Audit.csv\", stringsAsFactors = TRUE)\n\n# Three continuous features, followed by five categorical features\nX = df[c(\"Age\", \"Hours\", \"Income\", \"Education\", \"Employment\", \"Gender\", \"Marital\", \"Occupation\")]\ny = df[\"Adjusted\"]\n\naudit.formula = formula(\"~ . - 1\")\naudit.frame = model.frame(audit.formula, data = X, na.action = na.pass)\n# Define rules for binarizing categorical features into binary indicator features\naudit.contrasts = lapply(X[sapply(X, is.factor)], contrasts, contrasts = FALSE)\n# Perform binarization\naudit.matrix = model.matrix(audit.formula, data = audit.frame, contrasts.arg = audit.contrasts)\n\n# Generate feature map based on audit.frame (not audit.matrix), because data.frame holds richer column meta-information than matrix\naudit.fmap = r2pmml::as.fmap(audit.frame)\nr2pmml::write.fmap(audit.fmap, \"Audit.fmap\")\n\naudit.xgb = xgboost(data = audit.matrix, label = as.matrix(y), objective = \"binary:logistic\", nrounds = 131)\nxgb.save(audit.xgb, \"XGBoostAudit.model\")\n```\n\n#### Python language - Learning API\n\nUsing an `Audit.fmap` feature map file (works with any XGBoost version):\n```python\nfrom sklearn2pmml.xgboost import make_feature_map\nfrom xgboost import DMatrix\n\nimport pandas\nimport xgboost\n\ndf = pandas.read_csv(\"Audit.csv\")\n\n# Three continuous features, followed by five categorical features\nX = df[[\"Age\", \"Hours\", \"Income\", \"Education\", \"Employment\", \"Gender\", \"Marital\", \"Occupation\"]]\ny = df[\"Adjusted\"]\n\n# Convert categorical features into binary indicator features\nX = pandas.get_dummies(data = X, prefix_sep = \"=\", dtype = bool)\n\naudit_fmap = make_feature_map(X, enable_categorical = False)\naudit_fmap.save(\"Audit.fmap\")\n\naudit_dmatrix = DMatrix(data = X, label = y)\n\naudit_xgb = xgboost.train(params = {\"objective\" : \"binary:logistic\"}, dtrain = audit_dmatrix, num_boost_round = 131)\naudit_xgb.save_model(\"XGBoostAudit.model\")\n```\n\nThe same, but using an embedded feature map (works with XGBoost 1.4 and newer):\n```python\nfrom xgboost import DMatrix\n\nimport pandas\nimport xgboost\n\ndef to_fmap_type(dtype):\n    # Continuous integers\n    if dtype == \"int\":\n        return \"int\"\n    # Continuous floats\n    elif dtype == \"float\":\n        return \"float\"\n    # Binary indicators (ie. 0/1 values) generated by pandas.get_dummies(X)\n    elif dtype == \"bool\":\n        return \"i\"\n    else:\n        raise ValueError(dtype)\n\ndf = pandas.read_csv(\"Audit.csv\")\n\n# Three continuous features, followed by five categorical features\nX = df[[\"Age\", \"Hours\", \"Income\", \"Education\", \"Employment\", \"Gender\", \"Marital\", \"Occupation\"]]\ny = df[\"Adjusted\"]\n\n# Convert categorical features into binary indicator features\nX = pandas.get_dummies(data = X, prefix_sep = \"=\", dtype = bool)\n\nfeature_names = X.columns.values\nfeature_types = [to_fmap_type(dtype) for dtype in X.dtypes]\n\n# Constructing a DMatrix with explicit feature names and feature types\naudit_dmatrix = DMatrix(data = X, label = y, feature_names = feature_names, feature_types = feature_types)\n\naudit_xgb = xgboost.train(params = {\"objective\" : \"binary:logistic\"}, dtrain = audit_dmatrix, num_boost_round = 131)\naudit_xgb.save_model(\"XGBoostAudit.model\")\n```\n\n#### Python language - Scikit-Learn API\n\nUsing an `Audit.fmap` feature map file (works with any XGBoost version):\n```python\nfrom sklearn.preprocessing import LabelEncoder\nfrom sklearn2pmml.xgboost import make_feature_map\nfrom xgboost.sklearn import XGBClassifier\n\nimport pandas\n\ndf = pandas.read_csv(\"Audit.csv\")\n\n# Three continuous features, followed by five categorical features\nX = df[[\"Age\", \"Hours\", \"Income\", \"Education\", \"Employment\", \"Gender\", \"Marital\", \"Occupation\"]]\ny = df[\"Adjusted\"]\n\n# Convert categorical features into binary indicator features\nX = pandas.get_dummies(data = X, prefix_sep = \"=\", dtype = bool)\n\nlabel_encoder = LabelEncoder()\ny = label_encoder.fit_transform(y)\n\naudit_fmap = make_feature_map(X, enable_categorical = False)\naudit_fmap.save(\"Audit.fmap\")\n\nclassifier = XGBClassifier(objective = \"binary:logistic\", n_estimators = 131)\nclassifier.fit(X, y)\n\naudit_xgb = classifier.get_booster()\naudit_xgb.save_model(\"XGBoostAudit.model\")\n```\n\n### The JPMML-XGBoost side of operations\n\nConverting the model file `XGBoostAudit.model` (binary data format) together with the associated feature map file `Audit.fmap` to a PMML file `XGBoostAudit.pmml`:\n```\njava -jar pmml-xgboost-example/target/pmml-xgboost-example-executable-1.9-SNAPSHOT.jar --model-input XGBoostAudit.model --fmap-input Audit.fmap --target-name Adjusted --pmml-output XGBoostAudit.pmml\n```\n\nIf the XGBoost model contains an embedded feature map, then the `--fmap-input` command-line option may be omitted.\n\nGetting help:\n```\njava -jar pmml-xgboost-example/target/pmml-xgboost-example-executable-1.9-SNAPSHOT.jar --help\n```\n\n# Documentation #\n\n* [Upgrading Scikit-Learn XGBoost pipelines](https://openscoring.io/blog/2023/02/06/upgrading_sklearn_xgboost_pipeline_pmml/)\n* [Training Python-based XGBoost accelerated failure time models](https://openscoring.io/blog/2023/01/28/python_xgboost_aft_pmml/)\n* [One-hot encoding categorical features in Scikit-Learn XGBoost pipelines](https://openscoring.io/blog/2022/04/12/onehot_encoding_sklearn_xgboost_pipeline/)\n* [Training Scikit-Learn TF(-IDF) plus XGBoost pipelines](https://openscoring.io/blog/2021/02/27/sklearn_tf_tfidf_xgboost_pipeline/)\n* [Stacking Scikit-Learn, LightGBM and XGBoost models](https://openscoring.io/blog/2020/01/02/stacking_sklearn_lightgbm_xgboost/)\n* [Extending Scikit-Learn with GBDT+LR ensemble models](https://openscoring.io/blog/2019/06/19/sklearn_gbdt_lr_ensemble/) (Using XGBoost models on the GBDT side of GBDT+LR ensemble)\n\n# License #\n\nJPMML-XGBoost 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 JPMML-XGBoost in a proprietary software project, then it is possible to enter into a licensing agreement which makes JPMML-XGBoost available under the terms and conditions of the [BSD 3-Clause License](https://opensource.org/licenses/BSD-3-Clause) instead.\n\n# Additional information #\n\nJPMML-XGBoost 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)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjpmml%2Fjpmml-xgboost","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjpmml%2Fjpmml-xgboost","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjpmml%2Fjpmml-xgboost/lists"}