Python PMML scoring library
Project description
PyPMML
PyPMML is a Python PMML scoring library, it really is the Python API for PMML4S.
Prerequisites
- Java >= 1.8
- Python 2.7 or >= 3.5
Dependencies
- Py4J
- Pandas (optional)
Installation
pip install pypmml
Or install the latest version from github:
pip install --upgrade git+https://github.com/autodeployai/pypmml.git
Usage
-
Load model from various sources, e.g. readable, file path, string, or an array of bytes.
from pypmml import Model # The model is from http://dmg.org/pmml/pmml_examples/KNIME_PMML_4.1_Examples/single_iris_dectree.xml model = Model.load('single_iris_dectree.xml')
-
Call
predict(data)
to predict new values that can be in different types, e.g. dict, json, Series or DataFrame of Pandas.# data in dict result = model.predict({'sepal_length': 5.1, 'sepal_width': 3.5, 'petal_length': 1.4, 'petal_width': 0.2}) >>> print(result) {'probability': 1.0, 'node_id': '1', 'probability_Iris-virginica': 0.0, 'probability_Iris-setosa': 1.0, 'probability_Iris-versicolor': 0.0, 'predicted_class': 'Iris-setosa'} # data in 'records' json result = model.predict('[{"sepal_length": 5.1, "sepal_width": 3.5, "petal_length": 1.4, "petal_width": 0.2}]') >>> print(result) [{"probability":1.0,"probability_Iris-versicolor":0.0,"probability_Iris-setosa":1.0,"probability_Iris-virginica":0.0,"predicted_class":"Iris-setosa","node_id":"1"}] # data in 'split' json result = model.predict('{"columns": ["sepal_length", "sepal_width", "petal_length", "petal_width"], "data": [[5.1, 3.5, 1.4, 0.2]]}') >>> print(result) {"columns":["predicted_class","probability","probability_Iris-setosa","probability_Iris-versicolor","probability_Iris-virginica","node_id"],"data":[["Iris-setosa",1.0,1.0,0.0,0.0,"1"]]}
How to work with Pandas
import pandas as pd # data in Series result = model.predict(pd.Series({'sepal_length': 5.1, 'sepal_width': 3.5, 'petal_length': 1.4, 'petal_width': 0.2})) >>> print(result) node_id 1 predicted_class Iris-setosa probability 1 probability_Iris-setosa 1 probability_Iris-versicolor 0 probability_Iris-virginica 0 Name: 0, dtype: object # The data is from here: http://dmg.org/pmml/pmml_examples/Iris.csv data = pd.read_csv('Iris.csv') # data in DataFrame result = model.predict(data) >>> print(result) node_id predicted_class probability probability_Iris-setosa probability_Iris-versicolor probability_Iris-virginica 0 1 Iris-setosa 1.000000 1.0 0.000000 0.000000 1 1 Iris-setosa 1.000000 1.0 0.000000 0.000000 .. ... ... ... ... ... ... 148 10 Iris-virginica 0.978261 0.0 0.021739 0.978261 149 10 Iris-virginica 0.978261 0.0 0.021739 0.978261 [150 rows x 6 columns]
Use PMML in Scala or Java
See the PMML4S project. PMML4S is a PMML scoring library for Scala. It provides both Scala and Java Evaluator API for PMML.
Use PMML in Spark
See the PMML4S-Spark project. PMML4S-Spark is a PMML scoring library for Spark as SparkML Transformer.
Use PMML in PySpark
See the PyPMML-Spark project. PyPMML-Spark is a Python PMML scoring library for PySpark as SparkML Transformer, it really is the Python API for PMML4s-Spark.
Deploy PMML as REST API
See the DaaS system that deploys AI & ML models in production at scale on Kubernetes.
Support
If you have any questions about the PyPMML library, please open issues on this repository.
Feedback and contributions to the project, no matter what kind, are always very welcome.
License
PyPMML is licensed under APL 2.0.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file pypmml-0.9.5.tar.gz
.
File metadata
- Download URL: pypmml-0.9.5.tar.gz
- Upload date:
- Size: 15.0 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0ac7d68dc28bf453c31481bddb4d395044f1c8d84842fe2100fe8ee8b63a85bd |
|
MD5 | 9322e06c970d3ffa95cb3d311ab1705f |
|
BLAKE2b-256 | 3aadfeb2389388d247fe12d14de64e48a3b610d06943dc22a5000bf88d670e9c |