if (m_log != null) {
m_log.statusMessage(statusMessagePrefix() + "remove");
}
// Instances dataset = m_incrementalEvent.getInstance().dataset();
Instances dataset = m_incrementalEvent.getStructure();
// default to the last column if no class is set
if (dataset.classIndex() < 0) {
stop();
String errorMessage = statusMessagePrefix()
+ "ERROR: no class attribute set in incoming stream!";
if (m_log != null) {
m_log.statusMessage(errorMessage);
m_log.logMessage("[" + getCustomName() + "] " + errorMessage);
} else {
System.err.println("[" + getCustomName() + "] " + errorMessage);
}
return;
// System.err.println("Classifier : setting class index...");
//dataset.setClassIndex(dataset.numAttributes()-1);
}
try {
// initialize classifier if m_trainingSet is null
// otherwise assume that classifier has been pre-trained in batch
// mode, *if* headers match
if (m_trainingSet == null || !m_trainingSet.equalHeaders(dataset)) {
if (!(m_ClassifierTemplate instanceof
weka.classifiers.UpdateableClassifier) &&
!(m_ClassifierTemplate instanceof
weka.classifiers.misc.InputMappedClassifier)) {
stop(); // stop all processing
if (m_log != null) {
String msg = (m_trainingSet == null)
? statusMessagePrefix()
+ "ERROR: classifier has not been batch "
+"trained; can't process instance events."
: statusMessagePrefix()
+ "ERROR: instance event's structure is different from "
+"the data that "
+ "was used to batch train this classifier; can't continue.";
m_log.logMessage("[Classifier] " + msg);
m_log.statusMessage(msg);
}
return;
}
if (m_ClassifierTemplate instanceof
weka.classifiers.misc.InputMappedClassifier) {
m_trainingSet = ((weka.classifiers.misc.InputMappedClassifier)m_Classifier).
getModelHeader(m_trainingSet);
/* // check to see if the classifier that gets loaded is updateable
weka.classifiers.Classifier tempC =
((weka.classifiers.misc.InputMappedClassifier)m_Classifier).getClassifier();
if (!(tempC instanceof weka.classifiers.UpdateableClassifier)) {
} */
}
if (m_trainingSet != null &&
(!dataset.equalHeaders(m_trainingSet))) {
if (m_log != null) {
String msg = statusMessagePrefix()
+ " WARNING : structure of instance events differ "
+"from data used in batch training this "
+"classifier. Resetting classifier...";
m_log.logMessage("[Classifier] " + msg);
m_log.statusMessage(msg);
}
m_trainingSet = null;
}
if (m_trainingSet == null) {
// initialize the classifier if it hasn't been trained yet
m_trainingSet = new Instances(dataset, 0);
m_Classifier = weka.classifiers.AbstractClassifier.makeCopy(m_ClassifierTemplate);
if (m_Classifier instanceof EnvironmentHandler && m_env != null) {
((EnvironmentHandler)m_Classifier).setEnvironment(m_env);
}
m_Classifier.buildClassifier(m_trainingSet);