2

Is there any piece of Apex code or Managed Package that is able to read and parse PMML models, and then evaluate them on a given set of data?

I cannot find anything directly, and hoped some of you might have seen such tool!

4
  • The closest I found was this idea, but of course, no dice. I suspect you could probably write something, but I also couldn't seem to find any existing tools.
    – sfdcfox
    May 7 '19 at 14:34
  • Thanks for helping in the search! That idea was also the only thing I could find ;-) So I've actually already started the work on a PMML parser and evaluation tool. A rule engine / logic parser was something I already had, so I extended it with an PMML importer, which now seems to work at least for decision trees... I'll keep you posted once I have something functional :-) May 8 '19 at 18:41
  • Awesome! I'd be excited to see what you come up with, if you can share 😁
    – sfdcfox
    May 8 '19 at 18:44
  • @sfdcfox see my answer below! We've been able to build something that actually works. Pretty cool :-) Jun 14 '19 at 8:59
0

We were not able to find anything existing so in the end we decided to build something ourselves.

It has full support for reading PMML Decision Tree and Regression models in XML and then evaluating them against Salesforce data to generate decisions and/or predictions.

The basis idea is like this

// Create input variables
Map<String,Object> parameters = new Map<String,Object>{
        'account' => new Account('Name'='Test'),
        'other' => 'Test'
};
// Load PMML model
String modelXML = '...';
// Run Decision Tree
Util_PMML.evaluateDecisionTree(modelXML, parameters);
// Read result score
String result = (String)parameters.get('result');

Unfortunately I can't provide all the inner workings because it is part of our BPM Engine package that we also sell commercially. So I gather this answer is pretty useless from a technical perspective, but at least we now know that it is actually possible in Salesforce, and I would be able to help you out further if you'd like.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.