Created by jiashuai on 17-10-30.
| 9 | // Created by jiashuai on 17-10-30. |
| 10 | // |
| 11 | class NuSVCTest : public ::testing::Test { |
| 12 | protected: |
| 13 | NuSVCTest() : test_dataset() {} |
| 14 | |
| 15 | DataSet train_dataset; |
| 16 | DataSet test_dataset; |
| 17 | SvmParam param; |
| 18 | vector<float_type> predict_y; |
| 19 | |
| 20 | float |
| 21 | load_dataset_and_train(string train_filename, string test_filename, float_type C, float_type gamma, float_type nu) { |
| 22 | train_dataset.load_from_file(train_filename); |
| 23 | test_dataset.load_from_file(test_filename); |
| 24 | param.gamma = gamma; |
| 25 | param.C = C; |
| 26 | param.nu = nu; |
| 27 | param.kernel_type = SvmParam::RBF; |
| 28 | param.svm_type = SvmParam::NU_SVC; |
| 29 | // param.probability = 1; |
| 30 | std::shared_ptr<SvmModel> model; |
| 31 | model.reset(new NuSVC()); |
| 32 | model->train(train_dataset, param); |
| 33 | predict_y = model->predict(test_dataset.instances(), 10000); |
| 34 | std::shared_ptr<Metric> metric; |
| 35 | metric.reset(new Accuracy()); |
| 36 | return metric->score(predict_y, test_dataset.y()); |
| 37 | } |
| 38 | }; |
| 39 | |
| 40 | TEST_F(NuSVCTest, test_set) { |
| 41 | EXPECT_NEAR(load_dataset_and_train(DATASET_DIR |
nothing calls this directly
no outgoing calls
no test coverage detected