cls.setEvaluator((ASEvaluation) m_AttributeEvaluatorEditor.getValue());
cls.setSearch((ASSearch) m_AttributeSearchEditor.getValue());
cmdClassifier = cls.getClass().getName() + " "
+ Utils.joinOptions(cls.getOptions());
AttributeSelection eval = null;
try {
if (m_CVBut.isSelected()) {
testMode = 1;
numFolds = Integer.parseInt(m_CVText.getText());
seed = Integer.parseInt(m_SeedText.getText());
if (numFolds <= 1) {
throw new Exception(Messages.getInstance().getString("AttributeSelectionPanel_StartAttributeSelection_Run_Exception_Text_First"));
}
}
if (classIndex >= 0) {
inst.setClassIndex(classIndex);
}
// Output some header information
m_Log.logMessage(Messages.getInstance().getString("AttributeSelectionPanel_StartAttributeSelection_Run_Log_LogMessage_Text_First") + ename);
m_Log.logMessage(Messages.getInstance().getString("AttributeSelectionPanel_StartAttributeSelection_Run_Log_LogMessage_Text_Second") + cmd);
m_Log.logMessage(Messages.getInstance().getString("AttributeSelectionPanel_StartAttributeSelection_Run_Log_LogMessage_Text_Third") + cmdFilter);
m_Log.logMessage(Messages.getInstance().getString("AttributeSelectionPanel_StartAttributeSelection_Run_Log_LogMessage_Text_Fourth") + cmdClassifier);
if (m_Log instanceof TaskLogger) {
((TaskLogger)m_Log).taskStarted();
}
outBuff.append(Messages.getInstance().getString("AttributeSelectionPanel_StartAttributeSelection_Run_OutBuffer_Text_First"));
outBuff.append(Messages.getInstance().getString("AttributeSelectionPanel_StartAttributeSelection_Run_OutBuffer_Text_Second") + ename);
if (evaluator instanceof OptionHandler) {
String [] o = ((OptionHandler) evaluator).getOptions();
outBuff.append(" " + Utils.joinOptions(o));
}
outBuff.append(Messages.getInstance().getString("AttributeSelectionPanel_StartAttributeSelection_Run_OutBuffer_Text_Third") + sname);
if (search instanceof OptionHandler) {
String [] o = ((OptionHandler) search).getOptions();
outBuff.append(" " + Utils.joinOptions(o));
}
outBuff.append(Messages.getInstance().getString("AttributeSelectionPanel_StartAttributeSelection_Run_OutBuffer_Text_Fourth"));
outBuff.append(Messages.getInstance().getString("AttributeSelectionPanel_StartAttributeSelection_Run_OutBuffer_Text_Fifth") + inst.relationName() + '\n');
outBuff.append(Messages.getInstance().getString("AttributeSelectionPanel_StartAttributeSelection_Run_OutBuffer_Text_Sixth") + inst.numInstances() + '\n');
outBuff.append(Messages.getInstance().getString("AttributeSelectionPanel_StartAttributeSelection_Run_OutBuffer_Text_Seventh") + inst.numAttributes() + '\n');
if (inst.numAttributes() < 100) {
for (int i = 0; i < inst.numAttributes(); i++) {
outBuff.append(" " + inst.attribute(i).name()
+ '\n');
}
} else {
outBuff.append(Messages.getInstance().getString("AttributeSelectionPanel_StartAttributeSelection_Run_OutBuffer_Text_Eigth"));
}
outBuff.append(Messages.getInstance().getString("AttributeSelectionPanel_StartAttributeSelection_Run_OutBuffer_Text_Nineth"));
switch (testMode) {
case 0: // select using all training
outBuff.append(Messages.getInstance().getString("AttributeSelectionPanel_StartAttributeSelection_Run_OutBuffer_Text_Tenth"));
break;
case 1: // CV mode
outBuff.append("" + numFolds + Messages.getInstance().getString("AttributeSelectionPanel_StartAttributeSelection_Run_OutBuffer_Text_Eleventh"));
break;
}
outBuff.append("\n");
m_History.addResult(name, outBuff);
m_History.setSingle(name);
// Do the feature selection and output the results.
m_Log.statusMessage(Messages.getInstance().getString("AttributeSelectionPanel_StartAttributeSelection_Run_Log_StatusMessage_Text"));
m_History.updateResult(name);
eval = new AttributeSelection();
eval.setEvaluator(evaluator);
eval.setSearch(search);
eval.setFolds(numFolds);
eval.setSeed(seed);
if (testMode == 1) {
eval.setXval(true);
}
switch (testMode) {
case 0: // select using training
m_Log.statusMessage(Messages.getInstance().getString("AttributeSelectionPanel_StartAttributeSelection_Run_Log_StatusMessage_Text_First"));
eval.SelectAttributes(inst);
break;
case 1: // CV mode
m_Log.statusMessage(Messages.getInstance().getString("AttributeSelectionPanel_StartAttributeSelection_Run_Log_StatusMessage_Text_Second"));
Random random = new Random(seed);
inst.randomize(random);
if (inst.attribute(classIndex).isNominal()) {
m_Log.statusMessage(Messages.getInstance().getString("AttributeSelectionPanel_StartAttributeSelection_Run_Log_StatusMessage_Text_Third"));
inst.stratify(numFolds);
}
for (int fold = 0; fold < numFolds;fold++) {
m_Log.statusMessage(Messages.getInstance().getString("AttributeSelectionPanel_StartAttributeSelection_Run_Log_StatusMessage_Text_Fourth")
+ (fold + 1) + Messages.getInstance().getString("AttributeSelectionPanel_StartAttributeSelection_Run_Log_StatusMessage_Text_Fifth"));
Instances train = inst.trainCV(numFolds, fold, random);
m_Log.statusMessage(Messages.getInstance().getString("AttributeSelectionPanel_StartAttributeSelection_Run_Log_StatusMessage_Text_Sixth")
+ (fold + 1) + Messages.getInstance().getString("AttributeSelectionPanel_StartAttributeSelection_Run_Log_StatusMessage_Text_Seventh"));
eval.selectAttributesCVSplit(train);
}
break;
default:
throw new Exception(Messages.getInstance().getString("AttributeSelectionPanel_StartAttributeSelection_Run_Exception_Text_Second"));
}
if (testMode == 0) {
outBuff.append(eval.toResultsString());
} else {
outBuff.append(eval.CVResultsString());
}
outBuff.append(Messages.getInstance().getString("AttributeSelectionPanel_StartAttributeSelection_Run_OutBuffer_Text_Thirteenth"));
m_History.updateResult(name);
m_Log.logMessage(Messages.getInstance().getString("AttributeSelectionPanel_StartAttributeSelection_Run_Log_LogMessage_Text_Fifth") + ename+" "+sname);
m_Log.statusMessage(Messages.getInstance().getString("AttributeSelectionPanel_StartAttributeSelection_Run_Log_StatusMessage_Text_Eigth"));
} catch (Exception ex) {
m_Log.logMessage(ex.getMessage());
m_Log.statusMessage(Messages.getInstance().getString("AttributeSelectionPanel_StartAttributeSelection_Run_Log_StatusMessage_Text_Ninth"));
} finally {
if (evaluator instanceof AttributeTransformer) {
try {
Instances transformed =
((AttributeTransformer)evaluator).transformedData(inst);
transformed.
setRelationName(Messages.getInstance().getString("AttributeSelectionPanel_StartAttributeSelection_Run_Transformed_SetRelationName_Text") + transformed.relationName());
FastVector vv = new FastVector();
vv.addElement(transformed);
m_History.addObject(name, vv);
} catch (Exception ex) {
System.err.println(ex);
ex.printStackTrace();
}
} else if (testMode == 0) {
try {
Instances reducedInst = eval.reduceDimensionality(inst);
FastVector vv = new FastVector();
vv.addElement(reducedInst);
m_History.addObject(name, vv);
} catch (Exception ex) {
ex.printStackTrace();