Package aima.core.learning.framework

Examples of aima.core.learning.framework.DataSet


  @Test
  public void testClassificationReturnedWhenAllExamplesHaveTheSameClassification()
      throws Exception {
    // tests RecursionBaseCase#2
    DataSet ds = DataSetFactory.getRestaurantDataSet();
    DecisionTreeLearner learner = new DecisionTreeLearner();

    DataSet ds2 = ds.emptyDataSet();

    // all 3 examples have the same classification (willWait = yes)
    ds2.add(ds.getExample(0));
    ds2.add(ds.getExample(2));
    ds2.add(ds.getExample(3));

    learner.train(ds2);
    Assert.assertEquals("Yes", learner.predict(ds.getExample(0)));
  }
View Full Code Here


  @Test
  public void testMajorityReturnedWhenAttributesToExamineIsEmpty()
      throws Exception {
    // tests RecursionBaseCase#2
    DataSet ds = DataSetFactory.getRestaurantDataSet();
    DecisionTreeLearner learner = new DecisionTreeLearner();

    DataSet ds2 = ds.emptyDataSet();

    // 3 examples have classification = "yes" and one ,"no"
    ds2.add(ds.getExample(0));
    ds2.add(ds.getExample(1));// "no"
    ds2.add(ds.getExample(2));
    ds2.add(ds.getExample(3));
    ds2.setSpecification(new MockDataSetSpecification("will_wait"));

    learner.train(ds2);
    Assert.assertEquals("Yes", learner.predict(ds.getExample(1)));
  }
View Full Code Here

    Assert.assertEquals("Yes", learner.predict(ds.getExample(1)));
  }

  @Test
  public void testInducedTreeClassifiesDataSetCorrectly() throws Exception {
    DataSet ds = DataSetFactory.getRestaurantDataSet();
    DecisionTreeLearner learner = new DecisionTreeLearner();
    learner.train(ds);
    int[] result = learner.test(ds);
    Assert.assertEquals(12, result[0]);
    Assert.assertEquals(0, result[1]);
View Full Code Here

  public void testDecisionListLearnerReturnsNegativeDLWhenDataSetEmpty()
      throws Exception {
    // tests first base case of DL Learner
    DecisionListLearner learner = new DecisionListLearner("Yes", "No",
        new MockDLTestFactory(null));
    DataSet ds = DataSetFactory.getRestaurantDataSet();
    DataSet empty = ds.emptyDataSet();
    learner.train(empty);
    Assert.assertEquals("No", learner.predict(ds.getExample(0)));
    Assert.assertEquals("No", learner.predict(ds.getExample(1)));
    Assert.assertEquals("No", learner.predict(ds.getExample(2)));
  }
View Full Code Here

  public void testDecisionListLearnerReturnsFailureWhenTestsEmpty()
      throws Exception {
    // tests second base case of DL Learner
    DecisionListLearner learner = new DecisionListLearner("Yes", "No",
        new MockDLTestFactory(new ArrayList<DLTest>()));
    DataSet ds = DataSetFactory.getRestaurantDataSet();
    learner.train(ds);
    Assert.assertEquals(DecisionListLearner.FAILURE,
        learner.predict(ds.getExample(0)));
  }
View Full Code Here

        learner.predict(ds.getExample(0)));
  }

  @Test
  public void testDecisionListTestRunOnRestaurantDataSet() throws Exception {
    DataSet ds = DataSetFactory.getRestaurantDataSet();
    DecisionListLearner learner = new DecisionListLearner("Yes", "No",
        new DLTestFactory());
    learner.train(ds);

    int[] result = learner.test(ds);
View Full Code Here

    Assert.assertEquals(0, result[1]);
  }

  @Test
  public void testCurrentBestLearnerOnRestaurantDataSet() throws Exception {
    DataSet ds = DataSetFactory.getRestaurantDataSet();
    CurrentBestLearner learner = new CurrentBestLearner("Yes");
    learner.train(ds);

    int[] result = learner.test(ds);
    Assert.assertEquals(12, result[0]);
View Full Code Here

  private static final String YES = "Yes";

  @Test
  public void testAdaBoostEnablesCollectionOfStumpsToClassifyDataSetAccurately()
      throws Exception {
    DataSet ds = DataSetFactory.getRestaurantDataSet();
    List<DecisionTree> stumps = DecisionTree.getStumpsFor(ds, YES, "No");
    List<Learner> learners = new ArrayList<Learner>();
    for (Object stump : stumps) {
      DecisionTree sl = (DecisionTree) stump;
      StumpLearner stumpLearner = new StumpLearner(sl, "No");
View Full Code Here

  }

  @Test
  public void testLoadsDatasetFile() throws Exception {

    DataSet ds = DataSetFactory.getRestaurantDataSet();
    Assert.assertEquals(12, ds.size());

    Example first = ds.getExample(0);
    Assert.assertEquals(YES, first.getAttributeValueAsString("alternate"));
    Assert.assertEquals("$$$", first.getAttributeValueAsString("price"));
    Assert.assertEquals("0-10",
        first.getAttributeValueAsString("wait_estimate"));
    Assert.assertEquals(YES, first.getAttributeValueAsString("will_wait"));
View Full Code Here

  }

  @Test
  public void testLoadsIrisDataSetWithNumericAndStringAttributes()
      throws Exception {
    DataSet ds = DataSetFactory.getIrisDataSet();
    Example first = ds.getExample(0);
    Assert.assertEquals("5.1",
        first.getAttributeValueAsString("sepal_length"));
  }
View Full Code Here

TOP

Related Classes of aima.core.learning.framework.DataSet

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.