Version: 8.3.0
PMMLlib Python examples

Update a model in an existing PMML file :

The updating is done in two steps:

  • 1 : delete the XML node of the model with method UnlinkNode();
  • 2 : re-create the model.
    PMMLlib p ( fileName, log );
    
    # Set the model
    p.SetCurrentModel( modelName, modelType );
    
    # Delete the XML node of the model
    p.UnlinkNode( );
    # Recreate the model with new parameters
    p.AddRegressionModel(« monModele », PMMLlib::kREGRESSION,  « regression » );
    p.AddDataField( ….);
    
    # Save the PMML file
    p.Write( );
    

Backup and update a model in an existing PMML file :

It is done in two steps:

  • 1 : backup the model in an XML node with name modelName_ with method BackupNode();
  • 2 : re-create the model.
    PMMLlib p ( fileName, log );
    
    # Set the model
    p.SetCurrentModel( « monModele », modelType );
    
    # Save the model in a new XML node
    p.BackupNode( );
    # Modify
    p.AddRegressionModel(« monModele », PMMLlib::kREGRESSION,  « regression » );
    p.AddDataField( ….);
    
    # Save the PMML file
    p.Write( );
    

Add a model in an existing PMML file :

PMMLlib p ( fileName, log );

# Create the model
p.AddRegressionModel(« monModele », PMMLlib::kREGRESSION,  « regression » );
p.AddDataField( ….);

# Save the PMML file
p.Write( );

Read a model and execute it :

P = PMMLlib( fileName, log );
p.SetCurrentModel( modelName, modelType );

pyStrCode = p.ExportPythonStr( « myPyFunc », « function header » ); 
exec pyStrCode;

# Eval myPyFunc which is now known as a python function
inputs = [1.,2.,3.,4.]
res = myPyFunc(inputs)