Java Reference
In-Depth Information
Listing 9-12
Applying classification model to compute predictions
1. . . .
2. public class CustomerAttrition {
3. . . .
4. //Create and save input objects for build task
5. public void input() throws JDMException {
6. . . .
7. //Create apply task input objects
8. //Create apply PhysicalDataSet
9. PhysicalDataSet pdsApply = pdsFactory.create("CUSTOMERS_APPLY_DATA", false);
10. dmeConn.saveObject("attrition_apply_data", pds, replaceExistingObject);
11. // Create apply settings
12. ClassificationApplySettingFactory csApplyFactory =
13. (ClassificationApplySettingFactory)dmeConn.getFactory(
14. "javax.datamining.supervised.classification.ClassificationApplySetting");
15. ClassificationApplySettings csApplySettings = csApplyFactory.create();
16. // Top prediction, probability and cost output
17. csApplySettings.mapTopPrediction(ClassificationApplyContent.predictedCategory,
18. "PredictedAttrition");
19. csApplySettings.mapTopPrediction(ClassificationApplyContent.probabity,
20. "Probability");
21. csApplySettings.mapTopPrediction(ClassificationApplyContent.cost,
22. "Cost");
23. // Specify carry forward attributes from the input dataset (source) to
24. // output dataset (destination)
25. Map sourceDestinationMap = new HashMap();
26. sourceDestinationMap.put("CUST_ID", "CustomerId");
27. csApplySettings.setSourceDestinationMap(sourceDestinationMap);
28. //Save apply settings object
29. dmeConn.saveObject( "attrition_apply_settings",
30. csApplySettings, replaceExistingObject );
31. }
32. //Create test task and execute it to compute test metrics
33. public boolean run() throws JDMException {
34. . . .
35. //After successful completion of the test task create and execute apply task
36. DataSetApplyTaskFactory csApplyTaskFactory =
37. (DataSetApplyTaskFactory)dmeConn.getFactory(
38. "javax.datamining.task.apply. DataSetApplyTask");
39. DataSetApplyTask csApplyTask =
40. csApplyTaskFactory.create(
41. "attrition_apply_data","attrition_apply_settings",
42. "attrition_model","attrition_top_prediction_apply_output");
43. dmeConn.saveObject( "attritionApplyTask", csApplyTask, replaceExistingObject );
44. ExecutionStatus testTaskStatus = dmeConn.execute("attrition_apply_task", timeOut);
45. if( ExecutionState.success.equals(testTaskStatus.getState() ) )
46. return true;
47. else
48. return false;
49. }
Search WWH ::




Custom Search