{"id":13467157,"url":"https://github.com/jpmml/jpmml-evaluator","last_synced_at":"2025-12-29T22:17:51.513Z","repository":{"id":14475976,"uuid":"17188215","full_name":"jpmml/jpmml-evaluator","owner":"jpmml","description":"Java Evaluator API for PMML","archived":false,"fork":false,"pushed_at":"2024-07-07T20:41:22.000Z","size":7185,"stargazers_count":888,"open_issues_count":17,"forks_count":256,"subscribers_count":61,"default_branch":"master","last_synced_at":"2024-08-01T15:07:52.360Z","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":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-02-25T21:07:42.000Z","updated_at":"2024-07-26T09:32:24.000Z","dependencies_parsed_at":"2022-08-28T05:31:24.406Z","dependency_job_id":null,"html_url":"https://github.com/jpmml/jpmml-evaluator","commit_stats":null,"previous_names":[],"tags_count":87,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jpmml%2Fjpmml-evaluator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jpmml%2Fjpmml-evaluator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jpmml%2Fjpmml-evaluator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jpmml%2Fjpmml-evaluator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jpmml","download_url":"https://codeload.github.com/jpmml/jpmml-evaluator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222100827,"owners_count":16931670,"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.653Z","updated_at":"2025-12-29T22:17:51.507Z","avatar_url":"https://github.com/jpmml.png","language":"Java","funding_links":[],"categories":["Java","人工智能"],"sub_categories":["机器学习"],"readme":"JPMML-Evaluator [![Build Status](https://github.com/jpmml/jpmml-evaluator/workflows/maven/badge.svg)](https://github.com/jpmml/jpmml-evaluator/actions?query=workflow%3A%22maven%22)\n===============\n\nJava Evaluator API for Predictive Model Markup Language (PMML).\n\n# Table of Contents #\n\n- [Features](#features)\n- [Prerequisites](#prerequisites)\n- [Installation](#installation)\n- [API](#api)\n- [Basic usage](#basic-usage)\n- [Advanced usage](#advanced-usage)\n    + [Loading models](#loading-models)\n    + [Querying the \"data schema\" of models](#querying-the-data-schema-of-models)\n    + [Evaluating models](#evaluating-models)\n- [Example applications](#example-applications)\n- [Documentation](#documentation)\n- [Support](#support)\n- [License](#license)\n- [Additional information](#additional-information)\n\n# Features #\n\nJPMML-Evaluator is *de facto* the reference implementation of the PMML specification versions 3.0, 3.1, 3.2, 4.0, 4.1, 4.2, 4.3 and 4.4 for the Java/JVM platform:\n\n* Pre-processing of input fields according to the [DataDictionary](https://dmg.org/pmml/v4-4-1/DataDictionary.html) and [MiningSchema](https://dmg.org/pmml/v4-4-1/MiningSchema.html) elements:\n  * Complete data type system.\n  * Complete operational type system.\n  * Treatment of outlier, missing and/or invalid values.\n* Model evaluation:\n  * [Association rules](https://dmg.org/pmml/v4-4-1/AssociationRules.html)\n  * [Cluster model](https://dmg.org/pmml/v4-4-1/ClusteringModel.html)\n  * [General regression](https://dmg.org/pmml/v4-4-1/GeneralRegression.html)\n  * [Naive Bayes](https://dmg.org/pmml/v4-4-1/NaiveBayes.html)\n  * [k-Nearest neighbors](https://dmg.org/pmml/v4-4-1/KNN.html)\n  * [Neural network](https://dmg.org/pmml/v4-4-1/NeuralNetwork.html)\n  * [Regression](https://dmg.org/pmml/v4-4-1/Regression.html)\n  * [Rule set](https://dmg.org/pmml/v4-4-1/RuleSet.html)\n  * [Scorecard](https://dmg.org/pmml/v4-4-1/Scorecard.html)\n  * [Support Vector Machine](https://dmg.org/pmml/v4-4-1/SupportVectorMachine.html)\n  * [Tree model](https://dmg.org/pmml/v4-4-1/TreeModel.html)\n  * [Ensemble model](https://dmg.org/pmml/v4-4-1/MultipleModels.html)\n* Post-processing of target fields according to the [Targets](https://dmg.org/pmml/v4-4-1/Targets.html) element:\n  * Rescaling and/or casting regression results.\n  * Replacing a missing regression result with the default value.\n  * Replacing a missing classification result with the map of prior probabilities.\n* Calculation of auxiliary output fields according to the [Output](https://dmg.org/pmml/v4-4-1/Output.html) element:\n  * Over 20 different result feature types.\n* Model verification according to the [ModelVerification](https://dmg.org/pmml/v4-4-1/ModelVerification.html) element.\n* Vendor extensions:\n  * Memory and security sandboxing.\n  * Java-backed model, expression and predicate types - integrate any 3rd party Java library into PMML data flow.\n  * MathML prediction reports.\n\nFor more information please see the [features.md](https://github.com/jpmml/jpmml-evaluator/blob/master/features.md) file.\n\nJPMML-Evaluator is interoperable with most popular statistics and data mining software:\n\n* [R](https://www.r-project.org/) and [Rattle](https://rattle.togaware.com/):\n  * [JPMML-R](https://github.com/jpmml/jpmml-r) library.\n  * [`r2pmml`](https://github.com/jpmml/r2pmml) package.\n  * [`pmml`](https://cran.r-project.org/package=pmml) and [`pmmlTransformations`](https://CRAN.R-project.org/package=pmmlTransformations) packages.\n* [Python](https://www.python.org/) and [Scikit-Learn](https://scikit-learn.org/):\n  * [JPMML-SkLearn](https://github.com/jpmml/jpmml-sklearn) library.\n  * [`sklearn2pmml`](https://github.com/jpmml/sklearn2pmml) package.\n* [Apache Spark](https://spark.apache.org/):\n  * [JPMML-SparkML](https://github.com/jpmml/jpmml-sparkml) library.\n  * [`pyspark2pmml`](https://github.com/pyspark2pmml) and [`sparklyr2pmml`](https://github.com/jpmml/sparklyr2pmml) packages.\n  * [`mllib.pmml.PMMLExportable`](https://spark.apache.org/docs/latest/api/java/org/apache/spark/mllib/pmml/PMMLExportable.html) interface.\n* [H2O.ai](https://www.h2o.ai/):\n  * [JPMML-H2O](https://github.com/jpmml/jpmml-h2o) library.\n* [XGBoost](https://github.com/dmlc/xgboost):\n  * [JPMML-XGBoost](https://github.com/jpmml/jpmml-xgboost) library.\n* [LightGBM](https://github.com/Microsoft/LightGBM):\n  * [JPMML-LightGBM](https://github.com/jpmml/jpmml-lightgbm) library.\n* [TensorFlow](https://tensorflow.org):\n  * [JPMML-TensorFlow](https://github.com/jpmml/jpmml-tensorflow) library.\n* [KNIME](https://www.knime.com/)\n* [RapidMiner](https://rapidminer.com/products/rapidminer-studio/)\n* [SAS](https://www.sas.com/en_us/software/analytics/enterprise-miner.html)\n* [SPSS](https://www-01.ibm.com/software/analytics/spss/)\n\nJPMML-Evaluator is fast and memory efficient. It can deliver one million scorings per second already on a desktop computer.\n\n# Prerequisites #\n\n* Java 11 or newer.\n\n# Installation #\n\nJPMML-Evaluator library JAR files (together with accompanying Java source and Javadocs JAR files) are released via [Maven Central Repository](https://repo1.maven.org/maven2/org/jpmml/).\n\nThe current version is **1.7.6** (28 November, 2025).\n\nThe main component of JPMML-Evaluator is `org.jpmml:pmml-evaluator`.\nHowever, in most application scenarios, this component is not included directly, but via a data format-specific runtime component(s) `org.jpmml:pmml-evaluator-${runtime}` that handle the loading and storage of PMML class model objects.\n\nThe recommended data format for PMML documents is XML, and the recommended implementation is [Jakarta XML Binding](https://eclipse-ee4j.github.io/jaxb-ri/) via the [Glassfish Metro](https://metro.java.net) JAXB runtime:\n\n```xml\n\u003cdependency\u003e\n\t\u003cgroupId\u003eorg.jpmml\u003c/groupId\u003e\n\t\u003cartifactId\u003epmml-evaluator-metro\u003c/artifactId\u003e\n\t\u003cversion\u003e1.7.6\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nAvailable components:\n\n| Component | Data format(s) |\n| --- | --- |\n| `org.jpmml:pmml-evaluator` | [Java serialization](https://docs.oracle.com/javase/8/docs/api/java/io/Serializable.html) |\n| `org.jpmml:pmml-evaluator-jackson`| JSON, YAML, TOML etc. via the [FasterXML Jackson](https://github.com/FasterXML/jackson) suite |\n| `org.jpmml:pmml-evaluator-kryo` | [Kryo serialization](https://github.com/EsotericSoftware/kryo) |\n| `org.jpmml:pmml-evaluator-metro` | XML via the [GlassFish Metro](https://metro.java.net) JAXB runtime |\n| `org.jpmml:pmml-evaluator-moxy` | JSON and XML via the [EclipseLink MOXy](https://www.eclipse.org/eclipselink) JAXB runtime |\n\n# API #\n\nCore types:\n\n* Interface `org.jpmml.evaluator.EvaluatorBuilder`\n  * Class `org.jpmml.evaluator.ModelEvaluatorBuilder` - Builds a `ModelEvaluator` instance based on an `org.dmg.pmml.PMML` instance\n    * Class `org.jpmml.evaluator.LoadingModelEvaluatorBuilder` - Builds a `ModelEvaluator` instance from a PMML byte stream or a PMML file\n    * Class `org.jpmml.evaluator.ServiceLoadingModelEvaluatorBuilder` - Builds a `ModelEvaluator` instance from a PMML service provider JAR file\n* Interface `org.jpmml.evaluator.Evaluator`\n  * Abstract class `org.jpmml.evaluator.ModelEvaluator` - Implements model evaluator functionality based on an `org.dmg.pmml.Model` instance\n    * Classes `org.jpmml.evaluator.\u003cModel\u003eEvaluator` (`GeneralRegressionModelEvaluator`, `MiningModelEvaluator`, `NeuralNetworkEvaluator`, `RegressionEvaluator`, `TreeModelEvaluator`, `SupportVectorMachineEvaluator` etc.)\n* Abstract class `org.jpmml.evaluator.ModelField`\n  * Abstract class `org.jpmml.evaluator.InputField` - Describes a model input field\n  * Abstract class `org.jpmml.evaluator.ResultField`\n    * Class `org.jpmml.evaluator.TargetField` - Describes a primary model result field\n    * Class `org.jpmml.evaluator.OutputField` - Describes a secondary model result field\n* Abstract class `org.jpmml.evaluator.FieldValue`\n  * Class `org.jpmml.evaluator.CollectionValue`\n  * Abstract class `org.jpmml.evaluator.ScalarValue`\n    * Class `org.jpmml.evaluator.ContinuousValue`\n    * Abstract class `org.jpmml.evaluator.DiscreteValue`\n      * Class `org.jpmml.evaluator.CategoricalValue`\n      * Class `org.jpmml.evaluator.OrdinalValue`\n* Utility class `org.jpmml.evaluator.EvaluatorUtil`\n* Utility class `org.jpmml.evaluator.FieldValueUtil`\n\nCore methods:\n\n* `EvaluatorBuilder`\n  * `#build()`\n* `Evaluator`\n  * `#verify()`\n  * `#getInputFields()`\n  * `#getTargetFields()`\n  * `#getOutputFields()`\n  * `#evaluate(Map\u003cString, ?\u003e)`\n* `InputField`\n  * `#prepare(Object)`\n\nData input/output:\n* Interface `java.util.Map` - Singular data record.\n  * Interface `org.jpmml.evaluator.AggregableMap`\n  * Interface `org.jpmml.evaluator.LaggableMap`\n* Class `org.jpmml.evaluator.Table` - Collection (pseudo-batch) of data records.\n* Class `org.jpmml.evaluator.TableReader`\n* Class `org.jpmml.evaluator.TableWriter`\n\nTarget value types:\n\n* Interface `org.jpmml.evaluator.Computable`\n  * Abstract class `org.jpmml.evaluator.AbstractComputable`\n    * Class `org.jpmml.evaluator.Classification`\n    * Class `org.jpmml.evaluator.Regression`\n    * Class `org.jpmml.evaluator.Vote`\n* Interface `org.jpmml.evaluator.ResultFeature`\n  * Interface `org.jpmml.evaluator.HasCategoricalResult`\n    * Interface `org.jpmml.evaluator.HasAffinity`\n      * Interface `org.jpmml.evaluator.HasAffinityRanking`\n    * Interface `org.jpmml.evaluator.HasConfidence`\n    * Interface `org.jpmml.evaluator.HasProbability`\n  * Interface `org.jpmml.evaluator.HasDisplayValue`\n  * Interface `org.jpmml.evaluator.HasEntityId`\n    * Interface `org.jpmml.evaluator.HasEntityAffinity`\n    * Interface `org.jpmml.evaluator.HasEntityIdRanking`\n  * Interface `org.jpmml.evaluator.HasPrediction`\n  * Interface `org.jpmml.evaluator.HasReasonCodeRanking`\n  * Interface `org.jpmml.evaluator.HasRuleValues`\n  * Interface `org.jpmml.evaluator.mining.HasSegmentResults`\n  * Interface `org.jpmml.evaluator.scorecard.HasPartialScores`\n  * Interface `org.jpmml.evaluator.tree.HasDecisionPath`\n* Abstract class `org.jpmml.evaluator.Report`\n* Utility class `org.jpmml.evaluator.ReportUtil`\n\nTarget value methods:\n\n* `Computable`\n  * `#getResult()`\n* `HasProbability`\n  * `#getProbability(String)`\n  * `#getProbabilityReport(String)`\n* `HasPrediction`\n  * `#getPrediction()`\n  * `#getPredictionReport()`\n\nException types:\n\n* Abstract class `org.jpmml.model.PMMLException`\n  * Abstract class `org.jpmml.model.MarkupException`\n    * Abstract class `org.jpmml.model.InvalidMarkupException`\n    * Abstract class `org.jpmml.model.MissingMarkupException`\n    * Abstract class `org.jpmml.model.UnsupportedMarkupException`\n  * Abstract class `org.jpmml.evaluator.EvaluationException`\n\n# Basic usage #\n\n```java\n// Building a model evaluator from a PMML file\nEvaluator evaluator = new LoadingModelEvaluatorBuilder()\n\t.load(new File(\"model.pmml\"))\n\t.build();\n\n// Perforing the self-check\nevaluator.verify();\n\n// Printing input (x1, x2, .., xn) fields\nList\u003cInputField\u003e inputFields = evaluator.getInputFields();\nSystem.out.println(\"Input fields: \" + inputFields);\n\n// Printing primary result (y) field(s)\nList\u003cTargetField\u003e targetFields = evaluator.getTargetFields();\nSystem.out.println(\"Target field(s): \" + targetFields);\n\n// Printing secondary result (eg. probability(y), decision(y)) fields\nList\u003cOutputField\u003e outputFields = evaluator.getOutputFields();\nSystem.out.println(\"Output fields: \" + outputFields);\n\n// Iterating through columnar data (eg. a CSV file, an SQL result set)\nwhile(true){\n\t// Reading a record from the data source\n\tMap\u003cString, ?\u003e arguments = readRecord();\n\tif(arguments == null){\n\t\tbreak;\n\t}\n\n\t// Evaluating the model\n\tMap\u003cString, ?\u003e results = evaluator.evaluate(arguments);\n\n\t// Decoupling results from the JPMML-Evaluator runtime environment\n\tresults = EvaluatorUtil.decodeAll(results);\n\n\t// Writing a record to the data sink\n\twriteRecord(results);\n}\n\n// Making the model evaluator eligible for garbage collection\nevaluator = null;\n```\n\n# Advanced usage #\n\n### Loading models ###\n\nThe PMML standard defines large number of model types.\nThe evaluation logic for each model type is encapsulated into a corresponding `ModelEvaluator` subclass.\n\nEven though `ModelEvaluator` subclasses can be instantiated and configured directly, the recommended approach is to follow the Builder design pattern as implemented by the `ModelEvaluatorBuilder` builder class.\n\nA model evaluator builder provides configuration and loading services.\n\nThe default configuration corresponds to most common needs.\nIt can be overriden to customize the behaviour of model evaluators for more specific needs.\nA model evaluator is given a copy of the configuration that was effective when the `ModelEvaluatorBuilder#build()` method was invoked. It is not affected by later configuration changes.\n\nFor example, creating two differently configured model evaluators from a `PMML` instance:\n```java\nimport org.jpmml.evaluator.reporting.ReportingValueFactoryFactory\n\nPMML pmml = ...;\n\nModelEvaluatorBuilder modelEvaluatorBuilder = new ModelEvaluatorBuilder(pmml);\n\nEvaluator evaluator = modelEvaluatorBuilder.build();\n\n// Activate the generation of MathML prediction reports\nmodelEvaluatorBuilder.setValueFactoryFactory(ReportingValueFactoryFactory.newInstance());\n\nEvaluator reportingEvaluator = modelEvaluatorBuilder.build();\n```\n\nConfigurations and model evaluators are fairly lightweight, which makes them cheap to create and destroy.\nHowever, for maximum performance, it is advisable to maintain a one-to-one mapping between `PMML`, `ModelEvaluatorBuilder` and `ModelEvaluator` instances (ie. an application should load a PMML byte stream or file exactly once, and then maintain and reuse the resulting model evaluator as long as needed).\n\nSome `ModelEvaluator` subclasses contain static caches that are lazily populated on a `PMML` instance basis.\nThis may cause the first `ModelEvaluator#evaluate(Map\u003cString, ?\u003e)` method invocation to take somewhat longer to complete (relative to all the subsequent method invocations).\nIf the model contains model verification data, then this \"warm-up cost\" is paid once and for all during the initial `ModelEvaluator#verify()` method invocation.\n\n### Thread safety ###\n\nThe `ModelEvaluatorBuilder` base class is thread safe.\nIt is permitted to construct and configure a central `ModelEvaluatorBuilder` instance, and invoke its `ModelEvaluatorBuilder#build()` method concurrently.\n\nSome `ModelEvaluatorBuilder` subclasses may extend the base class with functionality that is not thread safe.\nThe case in point are all sorts of \"loading\" implementations, which modify the value of `ModelEvaluatorBuilder#pmml` and/or `ModelEvaluatorBuilder#model` fields.\n\nThe `ModelEvaluator` base class and all its subclasses are completely thread safe.\nIt is permitted to share a central `ModelEvaluator` instance between any number of threads, and invoke its `ModelEvaluator#evaluate(Map\u003cString, ?\u003e)` method concurrently.\n\nThe JPMML-Evaluator library follow functional programming principles.\nIn a multi-threaded environment, its data throughput capabilities should scale linearly with respect to the number of threads.\n\n### Querying the \"data schema\" of models ###\n\nThe model evaluator can be queried for the list of input (ie. independent), target (ie. primary dependent) and output (ie. secondary dependent) field definitions, which provide information about field name, data type, operational type, value domain etc.\n\nQuerying and analyzing input fields:\n```java\nList\u003c? extends InputField\u003e inputFields = evaluator.getInputFields();\nfor(InputField inputField : inputFields){\n\torg.dmg.pmml.DataField pmmlDataField = (org.dmg.pmml.DataField)inputField.getField();\n\torg.dmg.pmml.MiningField pmmlMiningField = inputField.getMiningField();\n\n\torg.dmg.pmml.DataType dataType = inputField.getDataType();\n\torg.dmg.pmml.OpType opType = inputField.getOpType();\n\n\tswitch(opType){\n\t\tcase CONTINUOUS:\n\t\t\tcom.google.common.collect.RangeSet\u003cDouble\u003e validInputRanges = inputField.getContinuousDomain();\n\t\t\tbreak;\n\t\tcase CATEGORICAL:\n\t\tcase ORDINAL:\n\t\t\tList\u003c?\u003e validInputValues = inputField.getDiscreteDomain();\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tbreak;\n\t}\n}\n```\n\nQuerying and analyzing target fields:\n```java\nList\u003c? extends TargetField\u003e targetFields = evaluator.getTargetFields();\nfor(TargetField targetField : targetFields){\n\torg.dmg.pmml.DataField pmmlDataField = targetField.getField();\n\torg.dmg.pmml.MiningField pmmlMiningField = targetField.getMiningField(); // Could be null\n\torg.dmg.pmml.Target pmmlTarget = targetField.getTarget(); // Could be null\n\n\torg.dmg.pmml.DataType dataType = targetField.getDataType();\n\torg.dmg.pmml.OpType opType = targetField.getOpType();\n\n\tswitch(opType){\n\t\tcase CONTINUOUS:\n\t\t\tbreak;\n\t\tcase CATEGORICAL:\n\t\tcase ORDINAL:\n\t\t\tList\u003c?\u003e validTargetValues = targetField.getDiscreteDomain();\n\n\t\t\t// The list of target category values for querying HasCategoricalResults subinterfaces (HasProbability, HasConfidence etc).\n\t\t\t// The default element type is String.\n\t\t\t// If the PMML instance is pre-parsed, then the element type changes to the appropriate Java primitive type\n\t\t\tList\u003c?\u003e categories = targetField.getCategories();\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tbreak;\n\t}\n}\n```\n\nQuerying and analyzing output fields:\n```java\nList\u003c? extends OutputField\u003e outputFields = evaluator.getOutputFields();\nfor(OutputField outputField : outputFields){\n\torg.dmg.pmml.OutputField pmmlOutputField = outputField.getOutputField();\n\n\torg.dmg.pmml.DataType dataType = outputField.getDataType(); // Could be null\n\torg.dmg.pmml.OpType opType = outputField.getOpType(); // Could be null\n\n\tboolean finalResult = outputField.isFinalResult();\n\tif(!finalResult){\n\t\tcontinue;\n\t}\n}\n```\n\n### Evaluating models ###\n\nA model may contain verification data, which is a small but representative set of data records (inputs plus expected outputs) for ensuring that the model evaluator is behaving correctly in this deployment configuration (JPMML-Evaluator version, Java/JVM version and vendor etc. variables).\nThe model evaluator should be verified once, before putting it into actual use.\n\nPerforming the self-check:\n```java\nevaluator.verify();\n```\n\nDuring scoring, the application code should iterate over data records (eg. rows of a table), and apply the following encode-evaluate-decode sequence of operations to each one of them.\n\nThe processing of the first data record will be significantly slower than the processing of all subsequent data records, because the model evaluator needs to lookup, validate and pre-parse model content.\nIf the model contains verification data, then this warm-up cost is borne during the self-check.\n\nPreparing the argument map:\n```java\nMap\u003cString, ?\u003e inputDataRecord = ...;\n\nMap\u003cString, FieldValue\u003e arguments = new LinkedHashMap\u003c\u003e();\n\nList\u003cInputField\u003e inputFields = evaluator.getInputFields();\nfor(InputField inputField : inputFields){\n\tString inputName = inputField.getName();\n\n\tObject rawValue = inputDataRecord.get(inputName);\n\n\t// Transforming an arbitrary user-supplied value to a known-good PMML value\n\t// The user-supplied value is passed through: 1) outlier treatment, 2) missing value treatment, 3) invalid value treatment and 4) type conversion\n\tFieldValue inputValue = inputField.prepare(rawValue);\n\n\targuments.put(inputName, inputValue);\n}\n```\n\nPerforming the evaluation:\n```java\nMap\u003cString, ?\u003e results = evaluator.evaluate(arguments);\n```\n\nExtracting primary results from the result map:\n```java\nList\u003cTargetField\u003e targetFields = evaluator.getTargetFields();\nfor(TargetField targetField : targetFields){\n\tString targetName = targetField.getName();\n\n\tObject targetValue = results.get(targetName);\n}\n```\n\nThe target value is either a Java primitive value (as a wrapper object) or a complex value as a `Computable` instance.\n\nA complex target value may expose additional information about the prediction by implementing appropriate `ResultFeature` subinterfaces:\n```java\n// Test for \"entityId\" result feature\nif(targetValue instanceof HasEntityId){\n\tHasEntityId hasEntityId = (HasEntityId)targetValue;\n\n\tHasEntityRegistry\u003c?\u003e hasEntityRegistry = (HasEntityRegistry\u003c?\u003e)evaluator;\n\tBiMap\u003cString, ? extends Entity\u003e entities = hasEntityRegistry.getEntityRegistry();\n\n\tEntity winner = entities.get(hasEntityId.getEntityId());\n}\n\n// Test for \"probability\" result feature\nif(targetValue instanceof HasProbability){\n\tHasProbability hasProbability = (HasProbability)targetValue;\n\n\tSet\u003c?\u003e categories = hasProbability.getCategories();\n\tfor(Object category : categories){\n\t\tDouble categoryProbability = hasProbability.getProbability(category);\n\t}\n}\n```\n\nA complex target value may hold a reference to the model evaluator that created it. It is adisable to decode it to a Java primitive value (ie. decoupling from the JPMML-Evaluator runtime environment) as soon as all the additional information has been retrieved:\n```java\nif(targetValue instanceof Computable){\n\tComputable computable = (Computable)targetValue;\n\n\ttargetValue = computable.getResult();\n}\n```\n\nExtracting secondary results from the result map:\n```java\nList\u003cOutputField\u003e outputFields = evaluator.getOutputFields();\nfor(OutputField outputField : outputFields){\n\tString outputName = outputField.getName();\n\n\tObject outputValue = results.get(outputName);\n}\n```\n\nThe output value is always a Java primitive value (as a wrapper object).\n\n# Example applications #\n\nModule `pmml-evaluator-example` exemplifies the use of the JPMML-Evaluator library.\n\nThis module can be built using [Apache Maven](https://maven.apache.org/):\n```\nmvn clean install\n```\n\nThe resulting uber-JAR file `target/pmml-evaluator-example-executable-1.7-SNAPSHOT.jar` contains the following command-line applications:\n* `org.jpmml.evaluator.example.EvaluationExample` [(source)](https://github.com/jpmml/jpmml-evaluator/blob/master/pmml-evaluator-example/src/main/java/org/jpmml/evaluator/example/EvaluationExample.java).\n* `org.jpmml.evaluator.example.TestingExample` [(source)](https://github.com/jpmml/jpmml-evaluator/blob/master/pmml-evaluator-example/src/main/java/org/jpmml/evaluator/example/TestingExample.java).\n\nEvaluating model `model.pmml` with data records from `input.csv`. The predictions are stored to `output.csv`:\n```\njava -cp target/pmml-evaluator-example-executable-1.7-SNAPSHOT.jar org.jpmml.evaluator.example.EvaluationExample --model model.pmml --input input.csv --output output.csv\n```\n\nEvaluating model `model.pmml` with data records from `input.csv`. The predictions are verified against data records from `expected-output.csv`:\n```\njava -cp target/pmml-evaluator-example-executable-1.7-SNAPSHOT.jar org.jpmml.evaluator.example.TestingExample --model model.pmml --input input.csv --expected-output expected-output.csv\n```\n\nGetting help:\n```\njava -cp target/pmml-evaluator-example-executable-1.7-SNAPSHOT.jar \u003capplication class name\u003e --help\n```\n\n# Documentation #\n\nUp-to-date:\n\n* [Benchmarking Scikit-Learn against JPMML-Evaluator in Java and Python environments](https://openscoring.io/blog/2021/08/04/benchmarking_sklearn_jpmml_evaluator/)\n* [Tracing and reporting ML model predictions](https://openscoring.io/blog/2019/02/26/jpmml_evaluator_api_tracing_reporting_predictions/)\n* [Upgrading from the Factory pattern to the Builder pattern](https://openscoring.io/blog/2018/12/06/jpmml_evaluator_api_builder_pattern/)\n\nSlightly outdated:\n\n* [Testing PMML applications](https://openscoring.io/blog/2014/05/12/testing_pmml_applications/)\n\n# Support #\n\nLimited public support is available via the [JPMML mailing list](https://groups.google.com/forum/#!forum/jpmml).\n\n# License #\n\nJPMML-Evaluator 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).\nFor a quick summary of your rights (\"Can\") and obligations (\"Cannot\" and \"Must\") under AGPLv3, please refer to [TLDRLegal](https://tldrlegal.com/license/gnu-affero-general-public-license-v3-(agpl-3.0)).\n\nIf you would like to use JPMML-Evaluator in a proprietary software project, then it is possible to enter into a licensing agreement which makes JPMML-Evaluator 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-Evaluator is developed and maintained by Openscoring OÜ, 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-evaluator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjpmml%2Fjpmml-evaluator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjpmml%2Fjpmml-evaluator/lists"}