Java Reference
In-Depth Information
Listing 9-4 gives the JDM code example that builds a classification
model for the customer attrition problem discussed in Section 7.1. The
CustomerAttrition class (line 6) builds a classification model called the
attrition_model using customers in CUSTOMERS_BUILD_DATA as
input data and the default classification settings. This class has four
methods: init , input , run , and output . The init method (line 29) creates
the DME connection and the object factories. The input method (line
41) creates and saves input object(s). The run method (line 49) exe-
cutes the task(s) and returns true if the tasks are successfully com-
pleted; otherwise it returns false . The output method (line 60) retrieves
the output object(s). Lastly, the reset method (line 65) removes the out-
put object(s) to reset the DME environment. In this chapter, we use
the CustomerAttrition Java class to illustrate the code for the JDM core
API and the classification-specific API. Listing 9-4 illustrates the use
of the Connection interface core methods.
The init method omits Connection creation code since it was intro-
duced in Section 9.1.1, but illustrates using Connection.getFactory to
create factory objects for the PhysicalDataSet , ClassificationSettings
input objects, and the BuildTask object. The input method instantiates
and saves input objects, as shown in lines 41 to 46. Objects are cre-
ated using the corresponding factory's create method, and saved
using the Connection.saveObject method. The saveObject method takes
a boolean flag replaceExistingObject as an argument to control
whether to replace an existing object with the new one. In the exam-
ple, this flag is set to true to replace an existing object with the same
name. Based on application requirements, this flag can be set to false ;
in this case, when there is an object name conflict the saveObject
method throws ObjectExistsException .
The run method creates a BuildTask object using the BuildTaskFac-
tory.create method (line 50). This method takes the names of the input
objects as arguments to create a task, namely, attritionBuildData , attri-
tionBuildSettings , and the name of the output object: attritionModel .
The Connection.execute method (line 53) executes the build task syn-
chr onously; the next section details task execution and monitoring.
The output method uses the Connection.retrieveObject method to get
the model from the DME .
Listing 9-4
CustomerAttrition example class that illustrates the use of the Connection interface
core methods
1. import*;
2. import javax.datamining.supervised.classification.*;
3. import javax.datamining.task.*;
Search WWH ::

Custom Search