Data Mining: Practical Machine Learning Tools and Techniques, Second Edition

(Brent) #1

14.2 GOING THROUGH THE CODE 467


}

// Check if there are any options left
Utils.checkForRemainingOptions(options);

// Process message.
if (classValue.length() != 0) {
messageCl.updateData(message.toString(), classValue);
} else {
messageCl.classifyMessage(message.toString());
}

// Save message classifier object.
ObjectOutputStream modelOutObjectFile =
new ObjectOutputStream(new FileOutputStream(modelName));
modelOutObjectFile.writeObject(messageCl);
modelOutObjectFile.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}

Figure 14.1(continued)


takes two parameters: the attribute’s name and a reference to a FastVector.If this
reference is null, as in the first application of this constructor in our program,
Weka creates an attribute of type string.Otherwise, a nominal attribute is
created. In that case it is assumed that the FastVectorholds the attribute values
as strings. This is how we create a class attribute with two values hitand miss:
by passing the attribute’s name (class)and its values—stored in a FastVector—
to Attribute().
To create a dataset from this attribute information,MessageClassifier()must
create an object of the class Instancesfrom the corepackage. The constructor
ofInstancesused by MessageClassifier()takes three arguments: the dataset’s
name, a FastVectorcontaining the attributes, and an integer indicating the
dataset’s initial capacity. We set the initial capacity to 100; it is expanded auto-
matically if more instances are added. After constructing the dataset,Message-
Classifier()sets the index of the class attribute to be the index of the last
attribute.
Free download pdf