[mlpack-git] master: Add a harder ARFF test. (535f0aa)
gitdub at big.cc.gt.atl.ga.us
gitdub at big.cc.gt.atl.ga.us
Wed Dec 23 11:45:02 EST 2015
Repository : https://github.com/mlpack/mlpack
On branch : master
Link : https://github.com/mlpack/mlpack/compare/de9cc4b05069e1fa4793d9355f2f595af5ff45d2...6070527af14296cd99739de6c62666cc5d2a2125
>---------------------------------------------------------------
commit 535f0aa68c1dc561d17c9af933d3bbe1c56471a9
Author: Ryan Curtin <ryan at ratml.org>
Date: Wed Oct 21 12:03:14 2015 -0400
Add a harder ARFF test.
I wouldn't call ARFF support completely 100% stable at this point, but it should
be good enough for most ARFF files out in the wild.
>---------------------------------------------------------------
535f0aa68c1dc561d17c9af933d3bbe1c56471a9
src/mlpack/tests/load_save_test.cpp | 59 +++++++++++++++++++++++++++++++++++++
1 file changed, 59 insertions(+)
diff --git a/src/mlpack/tests/load_save_test.cpp b/src/mlpack/tests/load_save_test.cpp
index 8b17b83..b533204 100644
--- a/src/mlpack/tests/load_save_test.cpp
+++ b/src/mlpack/tests/load_save_test.cpp
@@ -1183,6 +1183,8 @@ BOOST_AUTO_TEST_CASE(SimpleARFFCategoricalTest)
BOOST_REQUIRE_EQUAL(dataset(2, 0), dataset(2, 2));
BOOST_REQUIRE_EQUAL(dataset(2, 1), dataset(2, 3));
BOOST_REQUIRE_NE(dataset(2, 0), dataset(2, 1));
+
+ remove("test.arff");
}
/**
@@ -1191,7 +1193,64 @@ BOOST_AUTO_TEST_CASE(SimpleARFFCategoricalTest)
*/
BOOST_AUTO_TEST_CASE(HarderARFFTest)
{
+ fstream f;
+ f.open("test.arff", fstream::out);
+ f << "@relation \t test" << endl;
+ f << endl;
+ f << endl;
+ f << "@attribute @@@@flfl numeric" << endl;
+ f << endl;
+ f << "\% comment" << endl;
+ f << "@attribute \"hello world\" string" << endl;
+ f << "@attribute 12345 integer" << endl;
+ f << "@attribute real real" << endl;
+ f << "@attribute \"blah blah blah \t \" numeric \% comment" << endl;
+ f << "\% comment" << endl;
+ f << "@data" << endl;
+ f << "1, one, 3, 4.5, 6" << endl;
+ f << "2, two, 4, 5.5, 7 \% comment" << endl;
+ f << "3, \"three five, six\", 5, 6.5, 8" << endl;
+ f.close();
+
+ arma::mat dataset;
+ DatasetInfo info;
+ data::Load("test.arff", dataset, info);
+ BOOST_REQUIRE_EQUAL(info.Dimensionality(), 5);
+
+ BOOST_REQUIRE(info.Type(0) == Datatype::numeric);
+
+ BOOST_REQUIRE(info.Type(1) == Datatype::categorical);
+ BOOST_REQUIRE_EQUAL(info.NumMappings(1), 3);
+
+ BOOST_REQUIRE(info.Type(2) == Datatype::numeric);
+ BOOST_REQUIRE(info.Type(3) == Datatype::numeric);
+ BOOST_REQUIRE(info.Type(4) == Datatype::numeric);
+
+ BOOST_REQUIRE_EQUAL(dataset.n_rows, 5);
+ BOOST_REQUIRE_EQUAL(dataset.n_cols, 3);
+
+ BOOST_REQUIRE_CLOSE(dataset(0, 0), 1.0, 1e-5);
+ BOOST_REQUIRE_CLOSE(dataset(0, 1), 2.0, 1e-5);
+ BOOST_REQUIRE_CLOSE(dataset(0, 2), 3.0, 1e-5);
+
+ BOOST_REQUIRE_NE(dataset(1, 0), dataset(1, 1));
+ BOOST_REQUIRE_NE(dataset(1, 1), dataset(1, 2));
+ BOOST_REQUIRE_NE(dataset(1, 0), dataset(1, 2));
+
+ BOOST_REQUIRE_CLOSE(dataset(2, 0), 3.0, 1e-5);
+ BOOST_REQUIRE_CLOSE(dataset(2, 1), 4.0, 1e-5);
+ BOOST_REQUIRE_CLOSE(dataset(2, 2), 5.0, 1e-5);
+
+ BOOST_REQUIRE_CLOSE(dataset(3, 0), 4.5, 1e-5);
+ BOOST_REQUIRE_CLOSE(dataset(3, 1), 5.5, 1e-5);
+ BOOST_REQUIRE_CLOSE(dataset(3, 2), 6.5, 1e-5);
+
+ BOOST_REQUIRE_CLOSE(dataset(4, 0), 6.0, 1e-5);
+ BOOST_REQUIRE_CLOSE(dataset(4, 1), 7.0, 1e-5);
+ BOOST_REQUIRE_CLOSE(dataset(4, 2), 8.0, 1e-5);
+
+ remove("test.arff");
}
BOOST_AUTO_TEST_SUITE_END();
More information about the mlpack-git
mailing list