IPM GROOVY – How to Execute Machine Learning Models Using a Custom Groovy Rule (BYOML)

I’ve been curious about how easy it was to use externally fully trained ML models in planning apps ever since Oracle released Bring Your Own Machine Learning in EPM. For those who have no past experience with Machine Learning, Given the massive knowledge base already available on the internet, getting started is pretty simple. ML Model training is not my area of expertise, so I don’t devote much time to it. For the time being, let the data scientists handle it.

Once the model has been successfully imported, the system creates two groovy based business rules. One rule is to be executed from the webform and the other rule is to be executed as a standalone one.

VALIDATING ML MODEL USING GUI & GROOVY

There are no hard and fast guidelines for following the Groovy rules generated during ML model import. If the use cases are straightforward, we can generate the prediction output using our own custom groovy rules. To make it easier, I’m going to use the ‘Run Before Save’ logic that I used previously which doesn’t need DataGridBuilder or GridDefinitionBuilder. Please see my previous post for instructions on how to calculate and update data using ‘Run Before Save’ rules.

Testing Model from front end

Open the imported model and go to the ‘Test’ tab to see if the model is producing the desired results.

Testing Model using Groovy Rule

I am going to use the same parameters using Groovy business rule and see if that creates the same output or not. Its generating the same output.

Groovy
String modelName = 'Volume Forecasting Model'
String modelPath = '/Library'

//define model
MlModel model = operation.application.getMlModel(modelPath, modelName)

//run prediction
MlPredictionStatus[] predictedValues = model.predict('P_100', 325000, 565, 4500)
List<Double> targetData = predictedValues.findAll{it.success}.collect{it.predictedValue.toDouble()}

println "Predicted output : $targetData"

Job Console:

EXTENDING THE RULE TO WEB FORM COMPATIBLE

The core principle of a groovy prediction model is really simple: if we send the proper number of arguments to the model, and the model is trained for the members that are passed on, it will generate prediction values.

I’m using the form below, which already has all of the source data and the target member.

Groovy Script to predict and submit data:

Groovy
String modelName = 'Volume Forecasting Model'
String modelPath = '/Library'

MlModel model = operation.application.getMlModel(modelPath, modelName)

//fetch details from form and run prediction
operation.grid.dataCellIterator('Volume').each { DataCell cell ->
	
    //get source info from cells
    String curProduct = cell.getMemberName('Product')
    Double industryVolume = cell.crossDimCell('Industry Volume').data
    Double price = cell.crossDimCell('Price').data
    Double promotions = cell.crossDimCell('Promotions').data
    
    //run predicted values
    MlPredictionStatus[] predictedValues = model.predict([curProduct, industryVolume, price, promotions] as String[])
    Double predictedData = predictedValues.findAll{it.success}.collect{it.predictedValue.toDouble()}?.getAt(0)
    
    //set volume data
    cell.data = predictedData
}

The goal is to show that utilising a machine learning model does not have to be difficult. The ‘Run Before Save’ rules have a limitation in that all members must be present in the form. With DataGridDefinitionBuilder and DataGridBuilder, we can address any type of problem for complex requirements. I’m looking forward to what the BYOML modules will bring in the future.

Hope this information is useful!