diff --git a/src/mlpack/methods/linear_svm/linear_svm_impl.hpp b/src/mlpack/methods/linear_svm/linear_svm_impl.hpp index 789cba8f1a..ff2876c441 100644 --- a/src/mlpack/methods/linear_svm/linear_svm_impl.hpp +++ b/src/mlpack/methods/linear_svm/linear_svm_impl.hpp @@ -95,6 +95,18 @@ const { Classify(data, scores); + #if ARMA_VERSION_MAJOR > 7 || ARMA_VERSION_MAJOR == 7 \ + && ARMA_VERSION_MINOR >= 300 + + // Prepare necessary data + labels.zeros(data.n_cols); + + labels = arma::conv_to>::from( + arma::index_max(scores)); + + #else + // Once the minimum version is Armadillo is increased, remove this part. + // Prepare necessary data labels.zeros(data.n_cols); double maxScore = 0; @@ -116,6 +128,7 @@ const // Set maximum probability to zero for next input. maxScore = 0; } + #endif } template diff --git a/src/mlpack/tests/linear_svm_test.cpp b/src/mlpack/tests/linear_svm_test.cpp index b06216191c..3f004714ee 100644 --- a/src/mlpack/tests/linear_svm_test.cpp +++ b/src/mlpack/tests/linear_svm_test.cpp @@ -573,9 +573,8 @@ BOOST_AUTO_TEST_CASE(LinearSVMFitIntercept) const double delta = 1.0; // Generate a two-Gaussian dataset, - // which can't be separated without adding the intercept term. - GaussianDistribution g1(arma::vec("1.0 1.0 1.0"), arma::eye(3, 3)); - GaussianDistribution g2(arma::vec("9.0 9.0 9.0"), arma::eye(3, 3)); + GaussianDistribution g1(arma::vec("1.0 9.0 1.0"), arma::eye(3, 3)); + GaussianDistribution g2(arma::vec("4.0 3.0 4.0"), arma::eye(3, 3)); arma::mat data(inputSize, points); arma::Row labels(points); @@ -710,7 +709,7 @@ BOOST_AUTO_TEST_CASE(LinearSVMPSGDSimpleTest) // Compare training accuracy to 1. const double acc = lsvm.ComputeAccuracy(dataset, labels); - BOOST_REQUIRE_CLOSE(acc, 1.0, 0.5); + BOOST_REQUIRE_CLOSE(acc, 1.0, 1.0); } /** @@ -756,7 +755,7 @@ BOOST_AUTO_TEST_CASE(LinearSVMParallelSGDTwoClasses) // Compare training accuracy to 1. const double acc = lsvm.ComputeAccuracy(data, labels); - BOOST_REQUIRE_CLOSE(acc, 1.0, 0.5); + BOOST_REQUIRE_CLOSE(acc, 1.0, 1.0); // Create test dataset. for (size_t i = 0; i < points / 2; i++) @@ -772,7 +771,7 @@ BOOST_AUTO_TEST_CASE(LinearSVMParallelSGDTwoClasses) // Compare test accuracy to 1. const double testAcc = lsvm.ComputeAccuracy(data, labels); - BOOST_REQUIRE_CLOSE(testAcc, 1.0, 0.6); + BOOST_REQUIRE_CLOSE(testAcc, 1.0, 1.0); } #endif