MCPcopy Create free account
hub / github.com/PointCloudLibrary/pcl / doCrossValidation

Method doCrossValidation

ml/src/svm_wrapper.cpp:69–118  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

67}
68
69void
70pcl::SVMTrain::doCrossValidation()
71{
72 int total_correct = 0;
73 double sumv = 0, sumy = 0, sumvv = 0, sumyy = 0, sumvy = 0;
74 double* target;
75
76 // number of fold for the cross validation (n of folds = number of splitting of the
77 // input dataset)
78 if (nr_fold_ < 2) {
79 fprintf(stderr, "n-fold cross validation: n must >= 2\n");
80 return;
81 }
82 target = Malloc(double, prob_.l);
83
84 svm_cross_validation(&prob_, &param_, nr_fold_, target); // perform cross validation
85
86 if (param_.svm_type == EPSILON_SVR || param_.svm_type == NU_SVR) {
87 double total_error = 0;
88 for (int i = 0; i < prob_.l; i++) {
89 double y = prob_.y[i];
90 double v = target[i];
91 total_error += (v - y) * (v - y);
92 sumv += v;
93 sumy += y;
94 sumvv += v * v;
95 sumyy += y * y;
96 sumvy += v * y;
97 }
98
99 pcl::console::print_info(" - Cross Validation Mean squared error = ");
100 pcl::console::print_value("%g\n", total_error / prob_.l);
101
102 pcl::console::print_info(" - Cross Validation Squared correlation coefficient = ");
103 pcl::console::print_value(
104 "%g\n",
105 ((prob_.l * sumvy - sumv * sumy) * (prob_.l * sumvy - sumv * sumy)) /
106 ((prob_.l * sumvv - sumv * sumv) * (prob_.l * sumyy - sumy * sumy)));
107 }
108 else {
109 for (int i = 0; i < prob_.l; i++)
110 if (target[i] == prob_.y[i])
111 ++total_correct;
112
113 pcl::console::print_info(" - Cross Validation Accuracy = ");
114 pcl::console::print_value("%g%%\n", 100.0 * total_correct / prob_.l);
115 }
116
117 free(target);
118}
119
120void
121pcl::SVMTrain::scaleFactors(std::vector<SVMData> training_set, svm_scaling& scaling)

Callers

nothing calls this directly

Calls 2

svm_cross_validationFunction · 0.85
print_valueFunction · 0.85

Tested by

no test coverage detected