src/mlpack/tests/adaboost_test.cpp
/**
 * This test case runs the AdaBoost.mh algorithm on the UCI Iris Dataset.  It
 * trains it on two thirds of the Iris dataset (iris_train.csv), and tests on
 * the remaining third of the dataset (iris_test.csv).  It tests the Classify()
 * function and checks for a satisfactory error rate.
 */
This test case runs the AdaBoost.mh algorithm on the UCI Iris Dataset.  It
trains it on two thirds of the Iris dataset (iris_train.csv), and tests on
the remaining third of the dataset (iris_test.csv).  It tests the Classify()
function and checks for a satisfactory error rate.
This test case runs the AdaBoost . mh algorithm on the UCI Iris Dataset . It trains it on two thirds of the Iris dataset ( iris_train . csv ) and tests on the remaining third of the dataset ( iris_test . csv ) . It tests the Classify () function and checks for a satisfactory error rate .
BOOST_AUTO_TEST_CASE(ClassifyTest_IRIS)
{
  arma::mat inputData;
  if (!data::Load("iris_train.csv", inputData))
    BOOST_FAIL("Cannot load test dataset iris_train.csv!");
  arma::Mat<size_t> labels;
  if (!data::Load("iris_train_labels.csv", labels))
    BOOST_FAIL("Cannot load labels for iris_train_labels.csv");
  const size_t numClasses = max(labels.row(0)) + 1;
  size_t perceptronIter = 800;
  Perceptron<> p(inputData, labels.row(0), numClasses, perceptronIter);
  size_t iterations = 50;
  double tolerance = 1e-10;
  AdaBoost<> a(inputData, labels.row(0), numClasses, p, iterations, tolerance);
  arma::mat testData;
  if (!data::Load("iris_test.csv", testData))
    BOOST_FAIL("Cannot load test dataset iris_test.csv!");
  arma::Row<size_t> predictedLabels(testData.n_cols);
  a.Classify(testData, predictedLabels);
  arma::Mat<size_t> trueTestLabels;
  if (!data::Load("iris_test_labels.csv", trueTestLabels))
    BOOST_FAIL("Cannot load test dataset iris_test_labels.csv!");
  size_t localError = 0;
  for (size_t i = 0; i < trueTestLabels.n_cols; i++)
    if (trueTestLabels(i) != predictedLabels(i))
      localError++;
  double lError = (double) localError / labels.n_cols;
  BOOST_REQUIRE_LE(lError, 0.30);
}
BOOST_AUTO_TEST_CASE ( ClassifyTest_IRIS ) { arma :: mat inputData ; if ( ! data :: Load ( " " , inputData ) ) BOOST_FAIL ( " " ) ; arma :: Mat < size_t > labels ; if ( ! data :: Load ( " " , labels ) ) BOOST_FAIL ( " " ) ; const size_t numClasses = max ( labels . row ( 0 ) ) + 1 ; size_t perceptronIter = 800 ; Perceptron < > p ( inputData , labels . row ( 0 ) , numClasses , perceptronIter ) ; size_t iterations = 50 ; double tolerance = 1e-10 ; AdaBoost < > a ( inputData , labels . row ( 0 ) , numClasses , p , iterations , tolerance ) ; arma :: mat testData ; if ( ! data :: Load ( " " , testData ) ) BOOST_FAIL ( " " ) ; arma :: Row < size_t > predictedLabels ( testData . n_cols ) ; a . Classify ( testData , predictedLabels ) ; arma :: Mat < size_t > trueTestLabels ; if ( ! data :: Load ( " " , trueTestLabels ) ) BOOST_FAIL ( " " ) ; size_t localError = 0 ; for ( size_t i = 0 ; i < trueTestLabels . n_cols ; i ++ ) if ( trueTestLabels ( i ) != predictedLabels ( i ) ) localError ++ ; double lError = ( double ) localError / labels . n_cols ; BOOST_REQUIRE_LE ( lError , 0.30 ) ; }
This test case runs the AdaBoost.mh algorithm on the UCI Iris Dataset.
This test case runs the AdaBoost . mh algorithm on the UCI Iris Dataset .
// Define your own weak learner, perceptron in this case. // Run the perceptron for perceptronIter iterations. // Define parameters for AdaBoost.