Package weka.test

Examples of weka.test.Regression


   * @throws Exception   if something goes wrong
   */
  public void testRegression() throws Exception {
    int    i;
    boolean  succeeded;
    Regression   reg;
    Instances   train;
    int    type;
   
    // don't bother if not working correctly
    if (m_Tester.hasClasspathProblems())
      return;
   
    reg = new Regression(this.getClass());
    succeeded = false;
    train = null;
   
    for (i = FIRST_CLASSTYPE; i <= LAST_CLASSTYPE + 1; i++) {
      // does the Associator support this type of class at all?
      if (!canPredict(i))
        continue;
       
      if (i == LAST_CLASSTYPE + 1)
  type = CheckAssociator.NO_CLASS;
      else
  type = i;

      train = m_Tester.makeTestDataset(
          42, m_Tester.getNumInstances(),
      m_NominalPredictors[i] ? 2 : 0,
      m_NumericPredictors[i] ? 1 : 0,
          m_StringPredictors[i] ? 1 : 0,
          m_DatePredictors[i] ? 1 : 0,
          m_RelationalPredictors[i] ? 1 : 0,
          2,
          type,
          m_multiInstanceHandler);
 
      try {
        m_RegressionResults[i] = useAssociator(train);
        succeeded = true;
        reg.println(m_RegressionResults[i]);
      }
      catch (Exception e) {
  String msg = e.getMessage().toLowerCase();
  if (msg.indexOf("not in classpath") > -1)
    return;

  m_RegressionResults[i] = null;
      }
    }
   
    if (!succeeded) {
      fail("Problem during regression testing: no successful predictions for any class type");
    }

    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);
      }
View Full Code Here


   * run without any pre-existing reference output, the reference version
   * is created.
   */
  public void testRegression() throws Exception {
    boolean  succeeded;
    Regression   reg;
    Instances   train;
   
    // don't bother if not working correctly
    if (m_Tester.hasClasspathProblems())
      return;
   
    reg       = new Regression(this.getClass());
    train     = null;
    succeeded = false;
   
    train = m_Tester.makeTestDataset(
  42, m_Tester.getNumInstances(),
  m_NominalPredictors ? 2 : 0,
  m_NumericPredictors ? 1 : 0,
  m_StringPredictors ? 1 : 0,
  m_DatePredictors ? 1 : 0,
  m_RelationalPredictors ? 1 : 0,
  m_multiInstanceHandler);
   
    try {
      m_RegressionResults = useClusterer(train);
      succeeded = true;
      reg.println(m_RegressionResults);
    }
    catch (Exception e) {
      String msg = e.getMessage().toLowerCase();
      if (msg.indexOf("not in classpath") > -1)
  return;
     
      m_RegressionResults = null;
    }
   
    if (!succeeded) {
      fail("Problem during regression testing: no successful output 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);
      }
View Full Code Here

   * is created.
   */
  public void testRegression() throws Exception {
    int    i;
    boolean  succeeded;
    Regression   reg;
    Instances   train;
   
    // don't bother if not working correctly
    if (m_Tester.hasClasspathProblems())
      return;
   
    reg = new Regression(this.getClass());
    succeeded = false;
    train = null;
   
    for (i = FIRST_CLASSTYPE; i <= LAST_CLASSTYPE; i++) {
      // does the scheme support this type of class at all?
      if (!canPredict(i))
        continue;
       
      train = m_Tester.makeTestDataset(
          42, m_Tester.getNumInstances(),
      m_NominalPredictors[i] ? 2 : 0,
      m_NumericPredictors[i] ? 1 : 0,
          m_StringPredictors[i] ? 1 : 0,
          m_DatePredictors[i] ? 1 : 0,
          m_RelationalPredictors[i] ? 1 : 0,
          2,
          i,
          m_multiInstanceHandler);
 
      try {
        m_RegressionResults[i] = useScheme(train);
        succeeded = true;
        reg.println(m_RegressionResults[i]);
      }
      catch (Exception e) {
  String msg = e.getMessage().toLowerCase();
  if (msg.indexOf("not in classpath") > -1)
    return;

  m_RegressionResults[i] = null;
      }
    }
   
    if (!succeeded) {
      fail("Problem during regression testing: no successful predictions for any class type");
    }

    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);
      }
View Full Code Here

   * object matches that in a reference version. When this test is
   * run without any pre-existing reference output, the reference version
   * is created. Uses J48 for this purpose.
   */
  public void testRegression() {
    Regression     reg;
    Instances     train;
    Instances     test;
    Instances     data;
    TestInstances  testInst;
    int     tot;
    int     mid;
    EvaluationUtils   evaluation;
    FastVector    regressionResults;
   
    reg = new Regression(this.getClass());

    // generate test data
    try {
      testInst = new TestInstances();
      testInst.setClassType(Attribute.NOMINAL);
      testInst.setNumNominal(5);
      testInst.setNumNominalValues(4);
      testInst.setNumNumeric(0);
      testInst.setNumDate(0);
      testInst.setNumString(0);
      testInst.setNumRelational(0);
      testInst.setNumInstances(100);
      data = testInst.generate();
    }
    catch (Exception e) {
      fail("Failed generating data: " + e);
      return;
    }
   
    // split data into train/test
    tot = data.numInstances();
    mid = tot / 2;
    train = null;
    test = null;
   
    try {
      train = new Instances(data, 0, mid);
      test = new Instances(data, mid, tot - mid);
      m_Classifier = new SerializedClassifier();
      m_Classifier.setModelFile(new File(MODEL_FILENAME));
    }
    catch (Exception e) {
      e.printStackTrace();
      fail("Problem setting up to use classifier: " + e);
    }

    evaluation = new EvaluationUtils();
    try {
      trainAndSerializeClassifier(train);
      regressionResults = evaluation.getTrainTestPredictions(m_Classifier, train, test);
      reg.println(predictionsToString(regressionResults));
    }
    catch (Exception e) {
      fail("Failed obtaining classifier predictions: " + e);
    }
   
    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);
      }
View Full Code Here

   * is created.
   */
  public void testRegression() throws Exception {
    int    i;
    boolean  succeeded;
    Regression   reg;
    Instances   train;
   
    // don't bother if not working correctly
    if (m_Tester.hasClasspathProblems())
      return;
   
    reg = new Regression(this.getClass());
    succeeded = false;
    train = null;
   
    for (i = FIRST_CLASSTYPE; i <= LAST_CLASSTYPE; i++) {
      // does the Kernel support this type of class at all?
      if (!canPredict(i))
        continue;
       
      train = m_Tester.makeTestDataset(
          42, m_Tester.getNumInstances(),
      m_NominalPredictors[i] ? 2 : 0,
      m_NumericPredictors[i] ? 1 : 0,
          m_StringPredictors[i] ? 1 : 0,
          m_DatePredictors[i] ? 1 : 0,
          m_RelationalPredictors[i] ? 1 : 0,
          2,
          i,
          m_multiInstanceHandler);
 
      try {
        m_RegressionResults[i] =   CheckKernel.attributeTypeToString(i)
               + " class:\n"
               + useKernel(train);
        succeeded = true;
        reg.println(m_RegressionResults[i]);
      }
      catch (Exception e) {
  String msg = e.getMessage().toLowerCase();
  if (msg.indexOf("not in classpath") > -1)
    return;

  m_RegressionResults[i] = null;
      }
    }
   
    if (!succeeded) {
      fail("Problem during regression testing: no successful predictions for any class type");
    }

    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);
      }
View Full Code Here

   * is created.
   */
  public void testRegression() throws Exception {
    int    i;
    boolean  succeeded;
    Regression   reg;
    Instances   train;
   
    // don't bother if not working correctly
    if (m_Tester.hasClasspathProblems())
      return;
   
    reg = new Regression(this.getClass());
    succeeded = false;
    train = null;
   
    for (i = FIRST_CLASSTYPE; i <= LAST_CLASSTYPE; i++) {
      // does the classifier support this type of class at all?
      if (!canPredict(i))
        continue;
       
      train = m_Tester.makeTestDataset(
          42, m_Tester.getNumInstances(),
      m_NominalPredictors[i] ? m_Tester.getNumNominal() : 0,
      m_NumericPredictors[i] ? m_Tester.getNumNumeric() : 0,
          m_StringPredictors[i] ? m_Tester.getNumString() : 0,
          m_DatePredictors[i] ? m_Tester.getNumDate() : 0,
          m_RelationalPredictors[i] ? m_Tester.getNumRelational() : 0,
          2,
          i,
          m_multiInstanceHandler);
 
      try {
        m_RegressionResults[i] = useClassifier(train);
        succeeded = true;
        reg.println(predictionsToString(m_RegressionResults[i]));
      }
      catch (Exception e) {
  String msg = e.getMessage().toLowerCase();
  if (msg.indexOf("not in classpath") > -1)
    return;

  m_RegressionResults[i] = null;
      }
    }
   
    if (!succeeded) {
      fail("Problem during regression testing: no successful predictions for any class type");
    }

    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);
      }
View Full Code Here

   * Describe <code>testRegression</code> method here.
   *
   */
  public void testRegression() {

    Regression reg = new Regression(this.getClass());
    Instances result = useFilter();
    reg.println(result.toString());
    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);
    }

    reg = new Regression(this.getClass());

    // Run the filter using deprecated calls to check it still works the same
    Instances icopy = new Instances(m_Instances);
    try {
      m_Filter.setInputFormat(icopy);
    } catch (Exception ex) {
      ex.printStackTrace();
      fail("Exception thrown on setInputFormat(): \n" + ex.getMessage());
    }
    try {
      for (int i = 0; i < icopy.numInstances(); i++) {
        m_Filter.input(icopy.instance(i));
      }
      m_Filter.batchFinished();
      result = m_Filter.getOutputFormat();
      weka.core.Instance processed;
      while ((processed = m_Filter.output()) != null) {
        result.add(processed);
      }
      assertNotNull(result);
    } catch (Exception ex) {
      ex.printStackTrace();
      fail("Exception thrown on useFilter(): \n" + ex.getMessage());
    }
    reg.println(result.toString());
    try {
      String diff = reg.diff();
      if (diff == null) {
        System.err.println("Warning: No reference available, creating.");
      } else if (!diff.equals("")) {
        fail("Regression test failed when using deprecated methods. Difference:\n" + diff);
      }
View Full Code Here

   * is created.
   */
  public void testRegression() {
    int    i;
    boolean  succeeded;
    Regression  reg;
   
    reg       = new Regression(this.getClass());
    succeeded = false;
   
    for (i = 0; i < m_Data.length; i++) {
      try {
        m_RegressionResults[i] = useTokenizer(m_Data[i]);
        succeeded = true;
        reg.println(predictionsToString(m_RegressionResults[i]));
      }
      catch (Exception e) {
  m_RegressionResults[i] = null;
      }
    }
   
    if (!succeeded) {
      fail("Problem during regression testing: no successful tokens generated for any string");
    }

    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);
      }
View Full Code Here

   * object matches that in a reference version. When this test is
   * run without any pre-existing reference output, the reference version
   * is created.
   */
  public void testRegression() {
    Regression  reg;
    FastVector  regressionResult;
   
    reg = new Regression(this.getClass());
   
    try {
      regressionResult = useNearestNeighbourSearch(m_Instances);
      reg.println(resultsToString(regressionResult));
    }
    catch (Exception e) {
      fail("Regression test failed: " + e);
    }
   
    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);
      }
View Full Code Here

   * Describe <code>testRegression</code> method here.
   *
   */
  public void testRegression() {

    Regression reg = new Regression(this.getClass());
    Instances result = useFilter();
    reg.println(result.toString());
    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);
    }

    reg = new Regression(this.getClass());

    // Run the filter using deprecated calls to check it still works the same
    Instances icopy = new Instances(m_Instances);
    try {
      m_Filter.setInputFormat(icopy);
    } catch (Exception ex) {
      ex.printStackTrace();
      fail("Exception thrown on setInputFormat(): \n" + ex.getMessage());
    }
    try {
      for (int i = 0; i < icopy.numInstances(); i++) {
        m_Filter.input(icopy.instance(i));
      }
      m_Filter.batchFinished();
      result = m_Filter.getOutputFormat();
      weka.core.Instance processed;
      while ((processed = m_Filter.output()) != null) {
        result.add(processed);
      }
      assertNotNull(result);
    } catch (Exception ex) {
      ex.printStackTrace();
      fail("Exception thrown on useFilter(): \n" + ex.getMessage());
    }
    reg.println(result.toString());
    try {
      String diff = reg.diff();
      if (diff == null) {
        System.err.println("Warning: No reference available, creating.");
      } else if (!diff.equals("")) {
        fail("Regression test failed when using deprecated methods. Difference:\n" + diff);
      }
View Full Code Here

TOP

Related Classes of weka.test.Regression

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.