[mlpack-git] master: Test Classify(). (3f9cb06)

gitdub at big.cc.gt.atl.ga.us gitdub at big.cc.gt.atl.ga.us
Wed Dec 23 11:45:04 EST 2015


Repository : https://github.com/mlpack/mlpack

On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/de9cc4b05069e1fa4793d9355f2f595af5ff45d2...6070527af14296cd99739de6c62666cc5d2a2125

>---------------------------------------------------------------

commit 3f9cb06ea842c2d208653791bc8d4d66600352f2
Author: ryan <ryan at ratml.org>
Date:   Thu Oct 22 09:43:29 2015 -0400

    Test Classify().


>---------------------------------------------------------------

3f9cb06ea842c2d208653791bc8d4d66600352f2
 src/mlpack/tests/hoeffding_tree_test.cpp | 38 ++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/src/mlpack/tests/hoeffding_tree_test.cpp b/src/mlpack/tests/hoeffding_tree_test.cpp
index d2dcc52..97183e3 100644
--- a/src/mlpack/tests/hoeffding_tree_test.cpp
+++ b/src/mlpack/tests/hoeffding_tree_test.cpp
@@ -729,4 +729,42 @@ BOOST_AUTO_TEST_CASE(BinaryNumericHoeffdingTreeTest)
   BOOST_REQUIRE_GT(batchCorrect, 8550);
 }
 
+/**
+ * Test majority probabilities.
+ */
+BOOST_AUTO_TEST_CASE(MajorityProbabilityTest)
+{
+  data::DatasetInfo info(1);
+  StreamingDecisionTree<HoeffdingSplit<>> tree(info, 1, 3);
+
+  // Feed the tree a few samples.
+  tree.Train(arma::vec("1"), 0);
+  tree.Train(arma::vec("2"), 0);
+  tree.Train(arma::vec("3"), 0);
+
+  size_t prediction;
+  double probability;
+  tree.Classify(arma::vec("1"), prediction, probability);
+
+  BOOST_REQUIRE_EQUAL(prediction, 0);
+  BOOST_REQUIRE_CLOSE(probability, 1.0, 1e-5);
+
+  // Make it impure.
+  tree.Train(arma::vec("4"), 1);
+  tree.Classify(arma::vec("3"), prediction, probability);
+
+  BOOST_REQUIRE_EQUAL(prediction, 0);
+  BOOST_REQUIRE_CLOSE(probability, 0.75, 1e-5);
+
+  // Flip the majority class.
+  tree.Train(arma::vec("4"), 1);
+  tree.Train(arma::vec("4"), 1);
+  tree.Train(arma::vec("4"), 1);
+  tree.Train(arma::vec("4"), 1);
+  tree.Classify(arma::vec("3"), prediction, probability);
+
+  BOOST_REQUIRE_EQUAL(prediction, 1);
+  BOOST_REQUIRE_CLOSE(probability, 0.625, 1e-5);
+}
+
 BOOST_AUTO_TEST_SUITE_END();



More information about the mlpack-git mailing list