Adding, updating, and removing PMML models
The Predictive Analytics Add-on supports adding, updating, and removing a PMML model at runtime.
To add, update, or remove a model in an EPL script
1. The Predictive Analytics Add-on also supports adding and removing resources at runtime through ModelManager API. ModelManager API can be accessed by calling getModelManager() on the ServiceHandler object received in service initialisation onServiceInitialised callback.
action onServiceInitialised(ServiceHandler servicehandler)
{
ModelManager modelmanager := serviceHandler.getModelManager();
//Add Model1 from PMML_PATH1
modelmanager.addModel("PMML_PATH1");
//Add Model2 from PMML_PATH2
modelmanager.addModel("PMML_PATH2");
...
...
//Update Model1 from another source PMML_PATH3
modelmanager.updateModel("Model1","PMML_PATH3");
...
...
//remove model when done
modelmanager.removeModel("Model1");
modelmanager.removeModel("Model2");
}
Any errors are reported through default callback onServiceError of service handler.
You can add custom callbacks for the above mentioned functions as described below:
action onServiceInitialised(ServiceHandler servicehandler)
{
ModelManager modelmanager := serviceHandler.getModelManager();
//Add Model1 from PMML_PATH1
modelmanager.addModelCb("PMML_PATH1", onStatus);
//Add Model2 from PMML_PATH2
modelmanager.addModelCb("PMML_PATH2", onStatus);
...
...
//Update Model1 from another source PMML_PATH3
modelmanager.updateModelCb("Model1","PMML_PATH3", onStatus);
...
...
//remove model when done
modelmanager.removeModelCb("Model1", onStatus);
modelmanager.removeModelCb("Model2", onStatus);
}
action onStatus(ServiceError serviceError)
{
log "Received status on configured callback:
"+serviceError.getErrorMessage();
}
For more information, refer to the samples at APAMA_HOME/samples/PredictiveAnalytics/EnergyData ModelManager