Java Reference
In-Depth Information
9.4.6
Applying a Model to a Single Record—Real-Time Scoring
JDM supports a single record apply operation to enable real-time
performance for interactive applications such as those used for
online retail or in support of call center representatives. Listing 9-13
shows the code that computes the likelihood (probability) of a cus-
tomer to attrite for the given customer profile. In this example, the
getCustomerAttritionProbability method takes the customer profile
record as input and returns the probability that the customer will
attrite. Lines 9 to 26 show the initial setup required to execute a
record apply task. This setup involves creating the apply settings
object and using the mapByCategory method to specify having the
probability for the attrite value Attriter in the apply output. This
step further involves creating a RecordApplyTask object. Subsequent
invocations will reuse the task and settings objects. The customer
profile is set using the setInputRecord as shown in line 27. Line 29
shows the synchronous execution of the record apply task. After the
completion of the RecordApplyTask , we can retrieve the output
record using the getOutputRecord method and further retrieve the
probability value using the PhysicalDataRecord.getValue method as
shown in line 31.
Listing 9-13
Single record apply operation (real-time scoring)
1. . . .
2. public class CustomerAttrition {
3. . . .
4. RecordApplyTask csRecordApplyTask = null;
5. //Create and save input objects for build task
6. public double getCustomerAttritionProbability(PhysicalDataRecord customerProfile)
7. throws JDMException {
8. //When first time called setup all input setting and create record apply task
9. if(csRecordApplyTask == null) {
10. //Create input objects for the apply task
11. ClassificationApplySettingFactory csApplyFactory =
12. (ClassificationApplySettingFactory)dmeConn.getFactory(
13. "javax.datamining.supervised.classification.ClassificationApplySetting");
14. ClassificationApplySettings csApplySettings = csApplyFactory.create();
15. //Use mapByCategory to get probability associated with the attriter value
16. csApplySettings.mapByCategory(ClassificationApplyContent.probabity,
17. "Attriter", "Probability");
18. dmeConn.saveObject("category_attrition_apply_settings", csApplySettings,
19. replaceExistingObject);
20. RecordApplyTaskFactory csRecordApplyTaskFactory =
21. (RecordApplyTaskFactory)dmeConn.getFactory(
22. "javax.datamining.task.apply.RecordApplyTask");
23. csRecordApplyTask =
Search WWH ::




Custom Search