MCPcopy Create free account
hub / github.com/davisking/dlib / run_test

Method run_test

dlib/test/svm_multiclass_linear.cpp:153–201  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

151
152 template <typename sample_type>
153 void run_test()
154 {
155 print_spinner();
156
157 typedef typename sample_type::value_type::second_type scalar_type;
158
159 std::vector<sample_type> samples;
160 std::vector<scalar_type> labels;
161
162 load_libsvm_formatted_data("iris.scale",samples, labels);
163
164 DLIB_TEST(samples.size() == 150);
165 DLIB_TEST(labels.size() == 150);
166
167 typedef sparse_linear_kernel<sample_type> kernel_type;
168 svm_multiclass_linear_trainer<kernel_type> trainer;
169 trainer.set_c(100);
170 trainer.set_epsilon(0.000001);
171
172 randomize_samples(samples, labels);
173 matrix<double> cv = cross_validate_multiclass_trainer(trainer, samples, labels, 4);
174
175 dlog << LINFO << "confusion matrix: \n" << cv;
176 const scalar_type cv_accuracy = sum(diag(cv))/sum(cv);
177 dlog << LINFO << "cv accuracy: " << cv_accuracy;
178 DLIB_TEST(cv_accuracy > 0.97);
179
180
181
182
183 {
184 print_spinner();
185 typedef matrix<scalar_type,0,1> dsample_type;
186 std::vector<dsample_type> dsamples = sparse_to_dense(samples);
187 DLIB_TEST(dsamples.size() == 150);
188
189 typedef linear_kernel<dsample_type> kernel_type;
190 svm_multiclass_linear_trainer<kernel_type> trainer;
191 trainer.set_c(100);
192
193 cv = cross_validate_multiclass_trainer(trainer, dsamples, labels, 4);
194
195 dlog << LINFO << "dense confusion matrix: \n" << cv;
196 const scalar_type cv_accuracy = sum(diag(cv))/sum(cv);
197 dlog << LINFO << "dense cv accuracy: " << cv_accuracy;
198 DLIB_TEST(cv_accuracy > 0.97);
199 }
200
201 }
202
203
204

Callers

nothing calls this directly

Calls 10

print_spinnerFunction · 0.85
randomize_samplesFunction · 0.85
sparse_to_denseFunction · 0.85
sumFunction · 0.50
diagFunction · 0.50
sizeMethod · 0.45
set_cMethod · 0.45
set_epsilonMethod · 0.45

Tested by

no test coverage detected