Java Examples for weka.classifiers.AbstractClassifierTest
The following java examples will help you to understand the usage of weka.classifiers.AbstractClassifierTest. These source code samples are taken from different open source projects.
Example 1
Project: sad-analyzer-master File: AbstractPMMLClassifierTest.java View source code |
public void testRegression() throws Exception {
PMMLClassifier classifier = null;
Instances testData = null;
EvaluationUtils evalUtils = null;
weka.test.Regression reg = new weka.test.Regression(this.getClass());
FastVector predictions = null;
boolean success = false;
for (int i = 0; i < m_modelNames.size(); i++) {
classifier = getClassifier((String) m_modelNames.elementAt(i));
testData = getData((String) m_dataSetNames.elementAt(i));
evalUtils = new EvaluationUtils();
try {
String className = classifier.getMiningSchema().getFieldsAsInstances().classAttribute().name();
Attribute classAtt = testData.attribute(className);
testData.setClass(classAtt);
predictions = evalUtils.getTestPredictions(classifier, testData);
success = true;
String predsString = weka.classifiers.AbstractClassifierTest.predictionsToString(predictions);
reg.println(predsString);
} catch (Exception ex) {
ex.printStackTrace();
String msg = ex.getMessage().toLowerCase();
if (msg.indexOf("not in classpath") > -1) {
return;
}
}
}
if (!success) {
fail("Problem during regression testing: no successful predictions generated");
}
try {
String diff = reg.diff();
if (diff == null) {
System.err.println("Warning: No reference available, creating.");
} else if (!diff.equals("")) {
fail("Regression test failed. Difference:\n" + diff);
}
} catch (java.io.IOException ex) {
fail("Problem during regression testing.\n" + ex);
}
}