src/mlpack/tests/adaboost_test.cpp
BOOST_AUTO_TEST_CASE(HammingLossIris_DS)
{
  arma::mat inputData;
  if (!data::Load("iris.csv", inputData))
    BOOST_FAIL("Cannot load test dataset iris.csv!");

  arma::Mat<size_t> labels;
  if (!data::Load("iris_labels.txt", labels))
    BOOST_FAIL("Cannot load labels for iris_labels.txt");

  // Define your own weak learner, decision stumps in this case.
  const size_t numClasses = 3;
  const size_t inpBucketSize = 6;
  DecisionStump<> ds(inputData, labels.row(0), numClasses, inpBucketSize);

  // Define parameters for AdaBoost.
  size_t iterations = 50;
  double tolerance = 1e-10;
  AdaBoost<DecisionStump<>> a(inputData, labels.row(0), numClasses, ds,
      iterations, tolerance);

  arma::Row<size_t> predictedLabels;
  a.Classify(inputData, predictedLabels);

  size_t countError = 0;
  for (size_t i = 0; i < labels.n_cols; i++)
    if (labels(i) != predictedLabels(i))
      countError++;
  double hammingLoss = (double) countError / labels.n_cols;

  BOOST_REQUIRE_LE(hammingLoss, a.ZtProduct());
}
/**
 * This test case runs the AdaBoost.mh algorithm on the UCI Iris dataset.  It
 * checks whether the Hamming loss breaches the upper bound, which is provided
 * by ztAccumulator.  This uses decision stumps as the weak learner.
 */
This test case runs the AdaBoost.mh algorithm on the UCI Iris dataset.  It
checks whether the Hamming loss breaches the upper bound, which is provided
by ztAccumulator.  This uses decision stumps as the weak learner.
This test case runs the AdaBoost . mh algorithm on the UCI Iris dataset . It checks whether the Hamming loss breaches the upper bound which is provided by ztAccumulator . This uses decision stumps as the weak learner .
BOOST_AUTO_TEST_CASE(HammingLossIris_DS)
{
  arma::mat inputData;
  if (!data::Load("iris.csv", inputData))
    BOOST_FAIL("Cannot load test dataset iris.csv!");
  arma::Mat<size_t> labels;
  if (!data::Load("iris_labels.txt", labels))
    BOOST_FAIL("Cannot load labels for iris_labels.txt");
  const size_t numClasses = 3;
  const size_t inpBucketSize = 6;
  DecisionStump<> ds(inputData, labels.row(0), numClasses, inpBucketSize);
  size_t iterations = 50;
  double tolerance = 1e-10;
  AdaBoost<DecisionStump<>> a(inputData, labels.row(0), numClasses, ds,
      iterations, tolerance);
  arma::Row<size_t> predictedLabels;
  a.Classify(inputData, predictedLabels);
  size_t countError = 0;
  for (size_t i = 0; i < labels.n_cols; i++)
    if (labels(i) != predictedLabels(i))
      countError++;
  double hammingLoss = (double) countError / labels.n_cols;
  BOOST_REQUIRE_LE(hammingLoss, a.ZtProduct());
}
BOOST_AUTO_TEST_CASE ( HammingLossIris_DS ) { arma :: mat inputData ; if ( ! data :: Load ( " " , inputData ) ) BOOST_FAIL ( " " ) ; arma :: Mat < size_t > labels ; if ( ! data :: Load ( " " , labels ) ) BOOST_FAIL ( " " ) ; const size_t numClasses = 3 ; const size_t inpBucketSize = 6 ; DecisionStump < > ds ( inputData , labels . row ( 0 ) , numClasses , inpBucketSize ) ; size_t iterations = 50 ; double tolerance = 1e-10 ; AdaBoost < DecisionStump < > > a ( inputData , labels . row ( 0 ) , numClasses , ds , iterations , tolerance ) ; arma :: Row < size_t > predictedLabels ; a . Classify ( inputData , predictedLabels ) ; size_t countError = 0 ; for ( size_t i = 0 ; i < labels . n_cols ; i ++ ) if ( labels ( i ) != predictedLabels ( i ) ) countError ++ ; double hammingLoss = ( double ) countError / labels . n_cols ; BOOST_REQUIRE_LE ( hammingLoss , a . ZtProduct ( ) ) ; }
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, decision stumps in this case. // Define parameters for AdaBoost.