@Override protected void setUp() throws Exception { m_Classifier = getClassifier(); m_Tester = getTester(); m_OptionTester = getOptionTester(); m_GOETester = getGOETester(); checkAttributes(true, false, false, false, false, false); checkAttributes(false, true, false, false, false, false); checkAttributes(false, false, true, false, false, false); checkAttributes(false, false, false, true, false, false); checkAttributes(false, false, false, false, true, false); if (!canPredict(i)) { continue; m_handleMissingPredictors[i] = checkMissingPredictors(i, 20, false); m_handleMissingClass[i] = checkMissingClass(i, 20, false);
/** * Tests whether the classifier can handle class attributes as Nth attribute. * In case of multi-instance classifiers it performs no tests, since the * multi-instance data has a fixed format (bagID,bag,class). * * @see CheckClassifier#canHandleClassAsNthAttribute(boolean, boolean, * boolean, boolean, boolean, boolean, int, int) * @see CheckClassifier#testsPerClassType(int, boolean, boolean, boolean) */ public void testClassAsNthAttribute() { int i; // multi-Instance data has fixed format! if (m_multiInstanceHandler) { return; } for (i = FIRST_CLASSTYPE; i <= LAST_CLASSTYPE; i++) { // does the classifier support this type of class at all? if (!canPredict(i)) { continue; } // first attribute m_handleClassAsFirstAttribute[i] = checkClassAsNthAttribute(i, 0); // second attribute m_handleClassAsSecondAttribute[i] = checkClassAsNthAttribute(i, 1); } }
/** * tests whether the classifier erroneously uses the class value of test * instances (if provided) * * @see CheckClassifier#doesntUseTestClassVal(boolean, boolean, boolean, * boolean, boolean, boolean, int) * @see CheckClassifier#testsPerClassType(int, boolean, boolean, boolean) */ public void testUseOfTestClassValue() { boolean[] result; int i; for (i = FIRST_CLASSTYPE; i <= LAST_CLASSTYPE; i++) { // does the classifier support this type of class at all? if (!canPredict(i)) { continue; } result = m_Tester.doesntUseTestClassVal(m_NominalPredictors[i], m_NumericPredictors[i], m_StringPredictors[i], m_DatePredictors[i], m_RelationalPredictors[i], m_multiInstanceHandler, i); if (!result[0]) { fail("Uses test class values (" + getClassTypeString(i) + " class)!"); } } }
/** * tests whether the classifier can handle missing predictors (20% and 100%) * * @see CheckClassifier#canHandleMissing(boolean, boolean, boolean, boolean, * boolean, boolean, int, boolean, boolean, int) * @see CheckClassifier#testsPerClassType(int, boolean, boolean, boolean) */ public void testMissingPredictors() { int i; for (i = FIRST_CLASSTYPE; i <= LAST_CLASSTYPE; i++) { // does the classifier support this type of class at all? if (!canPredict(i)) { continue; } // 20% missing checkMissingPredictors(i, 20, true); // 100% missing if (m_handleMissingPredictors[i]) { checkMissingPredictors(i, 100, true); } } }
/** * tests whether the classifier can handle missing class values (20% and 100%) * * @see CheckClassifier#canHandleMissing(boolean, boolean, boolean, boolean, * boolean, boolean, int, boolean, boolean, int) * @see CheckClassifier#testsPerClassType(int, boolean, boolean, boolean) */ public void testMissingClass() { int i; for (i = FIRST_CLASSTYPE; i <= LAST_CLASSTYPE; i++) { // does the classifier support this type of class at all? if (!canPredict(i)) { continue; } // 20% missing checkMissingClass(i, 20, true); // 100% missing if (m_handleMissingClass[i]) { checkMissingClass(i, 100, true); } } }
/** * checks whether the classifier can handle the given percentage of missing * class labels * * @param type the class type * @param percent the percentage of missing class labels * @param allowFail if true a fail statement may be executed * @return true if the classifier can handle it */ protected boolean checkMissingClass(int type, int percent, boolean allowFail) { boolean[] result; result = m_Tester.canHandleMissing(m_NominalPredictors[type], m_NumericPredictors[type], m_StringPredictors[type], m_DatePredictors[type], m_RelationalPredictors[type], m_multiInstanceHandler, type, false, true, percent); if (allowFail) { if (!result[0] && !result[1]) { fail("Error handling " + percent + "% missing class labels (" + getClassTypeString(type) + " class)!"); } } return result[0]; }
if (!canPredict(i)) { continue; m_RegressionResults[i] = useClassifier(train); succeeded = true; reg.println(predictionsToString(m_RegressionResults[i])); } catch (Exception e) { String msg = e.getMessage().toLowerCase(); fail("Problem during regression testing: no successful predictions for any class type"); System.err.println("Warning: No reference available, creating."); } else if (!diff.equals("")) { fail("Regression test failed. Difference:\n" + diff); fail("Problem during regression testing.\n" + ex);
/** * configures the CheckClassifier instance used throughout the tests * * @return the fully configured CheckClassifier instance used for testing */ protected CheckClassifier getTester() { CheckClassifier result; result = super.getTester(); result.setNumInstances(40); return result; }
/** * tests whether the scheme declares a serialVersionUID. */ public void testSerialVersionUID() { boolean[] result; result = m_Tester.declaresSerialVersionUID(); if (!result[0]) { fail("Doesn't declare serialVersionUID!"); } }
/** * tests whether classifier handles N classes * * @see CheckClassifier#canHandleNClasses(boolean, boolean, boolean, boolean, * boolean, boolean, int) * @see CheckClassifier#testsPerClassType(int, boolean, boolean, boolean) * @see #m_NClasses */ public void testNClasses() { boolean[] result; if (!canPredict(Attribute.NOMINAL)) { return; } result = m_Tester.canHandleNClasses(m_NominalPredictors[Attribute.NOMINAL], m_NumericPredictors[Attribute.NOMINAL], m_StringPredictors[Attribute.NOMINAL], m_DatePredictors[Attribute.NOMINAL], m_RelationalPredictors[Attribute.NOMINAL], m_multiInstanceHandler, m_NClasses); if (!result[0] && !result[1]) { fail("Error handling " + m_NClasses + " classes!"); } }
/** * tests whether the classifier handles instance weights correctly * * @see CheckClassifier#instanceWeights(boolean, boolean, boolean, boolean, * boolean, boolean, int) * @see CheckClassifier#testsPerClassType(int, boolean, boolean, boolean) */ public void testInstanceWeights() { boolean[] result; int i; if (m_weightedInstancesHandler) { for (i = FIRST_CLASSTYPE; i <= LAST_CLASSTYPE; i++) { // does the classifier support this type of class at all? if (!canPredict(i)) { continue; } result = m_Tester.instanceWeights(m_NominalPredictors[i], m_NumericPredictors[i], m_StringPredictors[i], m_DatePredictors[i], m_RelationalPredictors[i], m_multiInstanceHandler, i); if (!result[0]) { System.err.println("Error handling instance weights (" + getClassTypeString(i) + " class)!"); } } } }
/** * Configures the CheckGOE used for testing GOE stuff. Sets the Classifier * returned from the getClassifier() method. * * @return the fully configured CheckGOE * @see #getClassifier() */ protected CheckGOE getGOETester() { CheckGOE result; result = new CheckGOE(); result.setObject(getClassifier()); result.setSilent(true); return result; }
/** * tests whether the classifier can handle different types of attributes and * if not, if the exception is OK * * @see #checkAttributes(boolean, boolean, boolean, boolean, boolean, boolean, * boolean) */ public void testAttributes() { // nominal checkAttributes(true, false, false, false, false, true); // numeric checkAttributes(false, true, false, false, false, true); // string checkAttributes(false, false, true, false, false, true); // date checkAttributes(false, false, false, true, false, true); // relational if (!m_multiInstanceHandler) { checkAttributes(false, false, false, false, true, true); } }
/** * checks whether the classifier can handle the given percentage of missing * predictors * * @param type the class type * @param percent the percentage of missing predictors * @param allowFail if true a fail statement may be executed * @return true if the classifier can handle it */ protected boolean checkMissingPredictors(int type, int percent, boolean allowFail) { boolean[] result; result = m_Tester.canHandleMissing(m_NominalPredictors[type], m_NumericPredictors[type], m_StringPredictors[type], m_DatePredictors[type], m_RelationalPredictors[type], m_multiInstanceHandler, type, true, false, percent); if (allowFail) { if (!result[0] && !result[1]) { fail("Error handling " + percent + "% missing predictors (" + getClassTypeString(type) + " class)!"); } } return result[0]; }
if (!canPredict(i)) { continue; m_RegressionResults[i] = useClassifier(train); succeeded = true; reg.println(predictionsToString(m_RegressionResults[i])); } catch (Exception e) { String msg = e.getMessage().toLowerCase(); fail("Problem during regression testing: no successful predictions for any class type"); System.err.println("Warning: No reference available, creating."); } else if (!diff.equals("")) { fail("Regression test failed. Difference:\n" + diff); fail("Problem during regression testing.\n" + ex);
/** * configures the CheckClassifier instance used throughout the tests * * @return the fully configured CheckClassifier instance used for testing */ protected CheckClassifier getTester() { CheckClassifier result; result = super.getTester(); result.setNumInstances(40); return result; }
/** * tests the setting of the options */ public void testSetOptions() { if (!m_OptionTester.checkSetOptions()) { fail("setOptions method failed."); } }
/** * tests whether classifier handles data containing only a class attribute * * @see CheckClassifier#canHandleOnlyClass(boolean, boolean, boolean, boolean, * boolean, int) * @see CheckClassifier#testsPerClassType(int, boolean, boolean, boolean) */ public void testOnlyClass() { boolean[] result; int i; for (i = FIRST_CLASSTYPE; i <= LAST_CLASSTYPE; i++) { // does the classifier support this type of class at all? if (!canPredict(i)) { continue; } result = m_Tester.canHandleOnlyClass(m_NominalPredictors[i], m_NumericPredictors[i], m_StringPredictors[i], m_DatePredictors[i], m_RelationalPredictors[i], i); if (!result[0] && !result[1]) { fail("Error handling data containing only the class!"); } } }
/** * tests whether the classifier handles instance weights correctly * * @see CheckClassifier#instanceWeights(boolean, boolean, boolean, boolean, * boolean, boolean, int) * @see CheckClassifier#testsPerClassType(int, boolean, boolean, boolean) */ public void testInstanceWeights() { boolean[] result; int i; if (m_weightedInstancesHandler) { for (i = FIRST_CLASSTYPE; i <= LAST_CLASSTYPE; i++) { // does the classifier support this type of class at all? if (!canPredict(i)) { continue; } result = m_Tester.instanceWeights(m_NominalPredictors[i], m_NumericPredictors[i], m_StringPredictors[i], m_DatePredictors[i], m_RelationalPredictors[i], m_multiInstanceHandler, i); if (!result[0]) { System.err.println("Error handling instance weights (" + getClassTypeString(i) + " class)!"); } } } }
/** * tests whether the classifier can handle missing predictors (20% and 100%) * * @see CheckClassifier#canHandleMissing(boolean, boolean, boolean, boolean, * boolean, boolean, int, boolean, boolean, int) * @see CheckClassifier#testsPerClassType(int, boolean, boolean, boolean) */ public void testMissingPredictors() { int i; for (i = FIRST_CLASSTYPE; i <= LAST_CLASSTYPE; i++) { // does the classifier support this type of class at all? if (!canPredict(i)) { continue; } // 20% missing checkMissingPredictors(i, 20, true); // 100% missing if (m_handleMissingPredictors[i]) { checkMissingPredictors(i, 100, true); } } }