src/mlpack/tests/logistic_regression_test.cpp
// Test training of logistic regression on a simple dataset with regularization.
Test training of logistic regression on a simple dataset with regularization.
Test training of logistic regression on a simple dataset with regularization .
BOOST_AUTO_TEST_CASE(LogisticRegressionLBFGSRegularizationSimpleTest)
{
  arma::mat data("1 2 3;"
                 "1 2 3");
  arma::Row<size_t> responses("1 1 0");
  LogisticRegression<> lr(data, responses, 0.001);
  arma::rowvec sigmoids = 1 / (1 + arma::exp(-lr.Parameters()[0]
      - lr.Parameters().tail_cols(lr.Parameters().n_elem - 1) * data));
  BOOST_REQUIRE_CLOSE(sigmoids[0], 1.0, 5.0);
  BOOST_REQUIRE_CLOSE(sigmoids[1], 1.0, 10.0);
  BOOST_REQUIRE_SMALL(sigmoids[2], 0.1);
}
BOOST_AUTO_TEST_CASE ( LogisticRegressionLBFGSRegularizationSimpleTest ) { arma :: mat data ( " " " " ) ; arma :: Row < size_t > responses ( " " ) ; LogisticRegression < > lr ( data , responses , 0.001 ) ; arma :: rowvec sigmoids = 1 / ( 1 + arma :: exp ( - lr . Parameters ( ) [ 0 ] - lr . Parameters ( ) . tail_cols ( lr . Parameters ( ) . n_elem - 1 ) * data ) ) ; BOOST_REQUIRE_CLOSE ( sigmoids [ 0 ] , 1.0 , 5.0 ) ; BOOST_REQUIRE_CLOSE ( sigmoids [ 1 ] , 1.0 , 10.0 ) ; BOOST_REQUIRE_SMALL ( sigmoids [ 2 ] , 0.1 ) ; }
Test training of logistic regression on a simple dataset with regularization.
Test training of logistic regression on a simple dataset with regularization .
// Very simple fake dataset. // Create a logistic regression object using L-BFGS (that is the default). // Test sigmoid function. // Large error tolerance is because the optimizer may terminate before // the predictions converge to 1.