Java Reference
In-Depth Information
28. (ClassificationTestMetrics)dmeConn.retrieveObject(
29. "attrition_test_metrics", NamedObject.testMetrics);
30. //Get model accuracy and confusion matrix details such as false prediction counts
31. ConfusionMatrix cfMatrix = clsTestMetrics.getConfusionMatrix();
32. double accuracy = cfMatrix.getAccuracy();
33. double error = cfMatrix.getError();
34. long falseNegatives = getNumberOfPredictions("Attriter", "Non-attriter");
35. long falsePositives = getNumberOfPredictions("Non-attriter", "Attriter");
36. //Get Lift object and cumulative lift and gain values to plot charts
37. Lift lift = clsTestMetrics.getLift();
38. double[] cumulativeLifts = new double[10];
39. double[] cumulativeGains = new double[10];
40. for(int quantile=1, index=0; qunatile <=10; quantile++, index++) {
41. cumulativeLifts[index] = lift.getCumulativeLift(quantile);
42. cumulativeGains[index] =
43. (double)lift.getCumulativePositiveCase(quantile)/(double)lift.getTotalCases();
44. }
45. //Get ROC object and retrieve true and false positive rates
46. //at various probability thresholds
47. ReceiverOperativeCurve roc = clsTestMetrics.getROC();
48. int numberOfThresholdPoints = roc.getNumberOfThresholdCandidates();
49. double[] thresholds = new double[numberOfThresholdPoints];
50. double[] truePositiveRates = new double[numberOfThresholdPoints];
51. double[] falsePositiveRates = new double[numberOfThresholdPoints];
52. for(int threshold=1, index=0; threshold <= numberOfThresholdPoints;
53. threshold++, index++) {
54. thresholds[index] = roc.getProbabilityThreshold(threshold);
55. truePositiveRates[index] = roc.getHitRate(threshold);
56. falsePositiveRates[index] = roc.getFalseAlarmRate(threshold);
57. }
58. }
9.4.5
Applying a Model to Data in Batch
After evaluating model performance, we often apply a model to new
data to predict target attribute values. JDM provides options for
applications to specify the content of apply output data according to
their requirements. In this section, we explore the interfaces related
to batch apply for classification models. Batch apply refers to applying
a model to cases stored in a database table or flat file.
Table 9-15 lists the interfaces related to the apply operation
including classification apply-specific interfaces. The task.apply pack-
age declares common interfaces used for model apply. The supervised.
classification package declares classification-specific apply settings
interfaces and an enumeration of classification-specific apply output
contents, such as predicted category, probability, cost, and node id .
 
Search WWH ::




Custom Search