Package: pypmml
PyPMMLPyPMMLis a Python PMML scoring library, it really is the Python API forPMML4S.PrerequisitesJava >= 8 and < 16Python 2.7 or >= 3.5DependenciesPy4JInstallationpipinstallpypmmlOr install the latest version from github:pipinstall--upgradegit+https://github.com/autodeployai/pypmml.gitUsageLoad model from various sources, e.g. readable, file path, string, or an array of bytes.frompypmmlimportModel# The model is from http://dmg.org/pmml/pmml_examples/KNIME_PMML_4.1_Examples/single_iris_dectree.xmlmodel=Model.load('single_iris_dectree.xml')Callpredict(data)to predict new values that can be in different types, e.g. dict, list, json, ndarray of NumPy, Series or DataFrame of Pandas.datain dict:>>>model.predict({'sepal_length':5.1,'sepal_width':3.5,'petal_length':1.4,'petal_width':0.2}){'probability_Iris-setosa':1.0,'probability_Iris-versicolor':0.0,'probability':1.0,'predicted_class':'Iris-setosa','probability_Iris-virginica':0.0,'node_id':'1'}datain list:NOTE: the order of values must match the input names, and the order of results always matches the output names.>>>model.inputNames['sepal_length','sepal_width','petal_length','petal_width']>>>model.predict([5.1,3.5,1.4,0.2])['Iris-setosa',1.0,1.0,0.0,0.0,'1']>>>model.outputNames['predicted_class','probability','probability_Iris-setosa','probability_Iris-versicolor','probability_Iris-virginica','node_id']datainrecordsjson:>>>model.predict('[{"sepal_length": 5.1, "sepal_width": 3.5, "petal_length": 1.4, "petal_width": 0.2}]')[{"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"}]datainsplitjson:>>>model.predict('{"columns": ["sepal_length", "sepal_width", "petal_length", "petal_width"], "data": [[5.1, 3.5, 1.4, 0.2]]}'){"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"]]}datain ndarray of NumPy:NOTE: as the list above, the order of ndarray values must match the input names, and the order of results always matches the output names.>>>importnumpyasnp>>>model.predict(np.array([5.1,3.5,1.4,0.2]))['Iris-setosa',1.0,1.0,0.0,0.0,'1']>>>>>>model.predict(np.array([[5.1,3.5,1.4,0.2],[7,3.2,4.7,1.4]]))[['Iris-setosa',1.0,1.0,0.0,0.0,'1'],['Iris-versicolor',0.9074074074074074,0.0,0.9074074074074074,0.09259259259259259,'3']]datain Series of Pandas:>>>importpandasaspd>>>model.predict(pd.Series({'sepal_length':5.1,'sepal_width':3.5,'petal_length':1.4,'petal_width':0.2}))node_id1predicted_classIris-setosaprobability1probability_Iris-setosa1probability_Iris-versicolor0probability_Iris-virginica0Name:0,dtype:objectdatain DataFrame of Pandas:>>>importpandasaspd>>>data=pd.read_csv('Iris.csv')# The data is from here: http://dmg.org/pmml/pmml_examples/Iris.csv>>>model.predict(data)node_idpredicted_classprobabilityprobability_Iris-setosaprobability_Iris-versicolorprobability_Iris-virginica01Iris-setosa1.0000001.00.0000000.00000011Iris-setosa1.0000001.00.0000000.00000021Iris-setosa1.0000001.00.0000000.00000031Iris-setosa1.0000001.00.0000000.00000041Iris-setosa1.0000001.00.0000000.000000....................14510Iris-virginica0.9782610.00.0217390.97826114610Iris-virginica0.9782610.00.0217390.97826114710Iris-virginica0.9782610.00.0217390.97826114810Iris-virginica0.9782610.00.0217390.97826114910Iris-virginica0.9782610.00.0217390.978261Use PMML in Scala or JavaSee thePMML4Sproject.PMML4Sis a PMML scoring library for Scala. It provides both Scala and Java Evaluator API for PMML.Use PMML in SparkSee thePMML4S-Sparkproject.PMML4S-Sparkis a PMML scoring library for Spark as SparkML Transformer.Use PMML in PySparkSee thePyPMML-Sparkproject.PyPMML-Sparkis a Python PMML scoring library for PySpark as SparkML Transformer, it really is the Python API for PMML4s-Spark.Deploy PMML as REST APISee theAI-Servingproject.AI-Servingis serving AI/ML models in the open standard formats PMML and ONNX with both HTTP (REST API) and gRPC endpoints.Deploy and Manage AI/ML models at scaleSee theDaaSsystem that deploys AI/ML models in production at scale on Kubernetes.SupportIf you have any questions about thePyPMMLlibrary, please open issues on this repository.Feedback and contributions to the project, no matter what kind, are always very welcome.LicensePyPMMLis licensed underAPL 2.0.