MCPcopy Create free account
hub / github.com/Xtra-Computing/thundersvm / predict_R

Function predict_R

src/thundersvm/svm_R_interface.cpp:287–336  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

285
286
287 void predict_R(char **test_file, char **model_file, char **out_file){
288 char model_file_path[1024] = DATASET_DIR;
289 char predict_file_path[1024] = DATASET_DIR;
290 char output_file_path[1024] = DATASET_DIR;
291 strcat(model_file_path, "../R/");
292 strcat(predict_file_path, "../R/");
293 strcat(output_file_path, "../R/");
294 strcpy(model_file_path, model_file[0]);
295 strcpy(predict_file_path, test_file[0]);
296 strcpy(output_file_path, out_file[0]);
297 fstream file;
298 file.open(model_file_path, std::fstream::in);
299 string feature, svm_type;
300 file >> feature >> svm_type;
301 CHECK_EQ(feature, "svm_type");
302 SvmModel *model = nullptr;
303 Metric *metric = nullptr;
304 if (svm_type == "c_svc") {
305 model = new SVC();
306 metric = new Accuracy();
307 } else if (svm_type == "nu_svc") {
308 model = new NuSVC();
309 metric = new Accuracy();
310 } else if (svm_type == "one_class") {
311 model = new OneClassSVC();
312 //todo determine a metric
313 } else if (svm_type == "epsilon_svr") {
314 model = new SVR();
315 metric = new MSE();
316 } else if (svm_type == "nu_svr") {
317 model = new NuSVR();
318 metric = new MSE();
319 }
320
321 model->load_from_file(model_file_path);
322 file.close();
323 file.open(output_file_path, std::fstream::out);
324 DataSet predict_dataset;
325 predict_dataset.load_from_file(predict_file_path);
326 vector<float_type> predict_y;
327 predict_y = model->predict(predict_dataset.instances(), 10000);
328 for (int i = 0; i < predict_y.size(); ++i) {
329 file << predict_y[i] << std::endl;
330 }
331 file.close();
332
333 if (metric) {
334 LOG(INFO) << metric->name() << " = " << metric->score(predict_y, predict_dataset.y());
335 }
336 }
337}

Callers

nothing calls this directly

Calls 6

instancesMethod · 0.80
nameMethod · 0.80
scoreMethod · 0.80
load_from_fileMethod · 0.45
predictMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected