src/mlpack/tests/logistic_regression_test.cpp
BOOST_AUTO_TEST_CASE(SinglePointClassifyTest)
{
  // Generate a two-Gaussian dataset.
  GaussianDistribution g1(arma::vec("1.0 1.0 1.0"), arma::eye<arma::mat>(3, 3));
  GaussianDistribution g2(arma::vec("9.0 9.0 9.0"), arma::eye<arma::mat>(3, 3));

  arma::mat data(3, 1000);
  arma::Row<size_t> responses(1000);
  for (size_t i = 0; i < 500; ++i)
  {
    data.col(i) = g1.Random();
    responses[i] = 0;
  }
  for (size_t i = 500; i < 1000; ++i)
  {
    data.col(i) = g2.Random();
    responses[i] = 1;
  }

  // Now train a logistic regression object on it.
  LogisticRegression<> lr(data.n_rows, 0.5);
  lr.Train<>(data, responses);

  // Create a test set.
  for (size_t i = 0; i < 500; ++i)
  {
    data.col(i) = g1.Random();
    responses[i] = 0;
  }
  for (size_t i = 500; i < 1000; ++i)
  {
    data.col(i) = g2.Random();
    responses[i] = 1;
  }

  arma::Row<size_t> predictions;
  lr.Classify(data, predictions);

  for (size_t i = 0; i < data.n_cols; ++i)
  {
    size_t pred = lr.Classify(data.col(i));

    BOOST_REQUIRE_EQUAL(pred, predictions[i]);
  }
}
/**
 * Test that single-point classification gives the same results as multi-point
 * classification.
 */
Test that single-point classification gives the same results as multi-point
classification.
Test that single - point classification gives the same results as multi - point classification .
BOOST_AUTO_TEST_CASE(SinglePointClassifyTest)
{
  GaussianDistribution g1(arma::vec("1.0 1.0 1.0"), arma::eye<arma::mat>(3, 3));
  GaussianDistribution g2(arma::vec("9.0 9.0 9.0"), arma::eye<arma::mat>(3, 3));
  arma::mat data(3, 1000);
  arma::Row<size_t> responses(1000);
  for (size_t i = 0; i < 500; ++i)
  {
    data.col(i) = g1.Random();
    responses[i] = 0;
  }
  for (size_t i = 500; i < 1000; ++i)
  {
    data.col(i) = g2.Random();
    responses[i] = 1;
  }
  LogisticRegression<> lr(data.n_rows, 0.5);
  lr.Train<>(data, responses);
  for (size_t i = 0; i < 500; ++i)
  {
    data.col(i) = g1.Random();
    responses[i] = 0;
  }
  for (size_t i = 500; i < 1000; ++i)
  {
    data.col(i) = g2.Random();
    responses[i] = 1;
  }
  arma::Row<size_t> predictions;
  lr.Classify(data, predictions);
  for (size_t i = 0; i < data.n_cols; ++i)
  {
    size_t pred = lr.Classify(data.col(i));
    BOOST_REQUIRE_EQUAL(pred, predictions[i]);
  }
}
BOOST_AUTO_TEST_CASE ( SinglePointClassifyTest ) { GaussianDistribution g1 ( arma :: vec ( " " ) , arma :: eye < arma :: mat > ( 3 , 3 ) ) ; GaussianDistribution g2 ( arma :: vec ( " " ) , arma :: eye < arma :: mat > ( 3 , 3 ) ) ; arma :: mat data ( 3 , 1000 ) ; arma :: Row < size_t > responses ( 1000 ) ; for ( size_t i = 0 ; i < 500 ; ++ i ) { data . col ( i ) = g1 . Random ( ) ; responses [ i ] = 0 ; } for ( size_t i = 500 ; i < 1000 ; ++ i ) { data . col ( i ) = g2 . Random ( ) ; responses [ i ] = 1 ; } LogisticRegression < > lr ( data . n_rows , 0.5 ) ; lr . Train < > ( data , responses ) ; for ( size_t i = 0 ; i < 500 ; ++ i ) { data . col ( i ) = g1 . Random ( ) ; responses [ i ] = 0 ; } for ( size_t i = 500 ; i < 1000 ; ++ i ) { data . col ( i ) = g2 . Random ( ) ; responses [ i ] = 1 ; } arma :: Row < size_t > predictions ; lr . Classify ( data , predictions ) ; for ( size_t i = 0 ; i < data . n_cols ; ++ i ) { size_t pred = lr . Classify ( data . col ( i ) ) ; BOOST_REQUIRE_EQUAL ( pred , predictions [ i ] ) ; } }
Test that single-point classification gives the same results as multi-point
 classification.
Test that single - point classification gives the same results as multi - point classification .
// Generate a two-Gaussian dataset. // Now train a logistic regression object on it. // Create a test set.