Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apply PMML predictor model in python

Knime has generated for me a PMML model. At this time I want to apply this model to a python process. What is the right way to do this?

More in depth: I develop a django student attendance system. The application is already so mature that I have time to implement the 'I'm feeling lucky' button to automatically fill an attendance form. Here is where PMML comes in. Knime has generated a PMML model that predicts student attendance. Also, thanks to django for being so productive that I time for this great work ;)

enter image description here

like image 390
dani herrera Avatar asked Mar 22 '13 18:03

dani herrera


People also ask

How do I load a PMML model?

Start by creating a new predictive model. Give your model a name and in the 'Create model' section, click Import PMML. Click Choose File and select the model file to upload.

How do I use PMML files?

To import a model saved as PMML See the topic Model types supporting PMML for more information. In the models palette, right-click the palette and select Import PMML from the menu. Select the file to import and specify options for variable labels as required. Click Open.

What is PMML format?

PMML stands for Predictive Model Markup Language. It is an XML-based file format developed by the Data Mining Group to provide a way for applications to describe and exchange models produced by data mining and machine learning algorithms.

What is model predict in Python?

model. predict() : given a trained model, predict the label of a new set of data. This method accepts one argument, the new data X_new (e.g. model. predict(X_new) ), and returns the learned label for each object in the array.


3 Answers

Finally I have wrote my own code. Be free to contribute or fork it:

https://github.com/ctrl-alt-d/lightpmmlpredictor

like image 188
dani herrera Avatar answered Oct 15 '22 21:10

dani herrera


The code for Augustus, to score PMML models in Python, is at https://code.google.com/p/augustus/

like image 23
Paco Avatar answered Oct 15 '22 20:10

Paco


You could use PyPMML to apply PMML in Python, for example:

from pypmml import Model

model = Model.fromFile('the/pmml/file/path')
result = model.predict(data)

The data could be dict, json, Series or DataFrame of Pandas.

If you use PMML in PySpark, you could use PyPMML-Spark, for example:

from pypmml_spark import ScoreModel

model = ScoreModel.fromFile('the/pmml/file/path')
score_df = model.transform(df)

The df is a DataFrame of PySpark.

For more info about other PMML libraries, be free to see: https://github.com/autodeployai

like image 30
PredictFuture Avatar answered Oct 15 '22 20:10

PredictFuture