MCPcopy Create free account
hub / github.com/arrayfire/arrayfire / bagging_demo

Function bagging_demo

examples/machine_learning/bagging.cpp:90–122  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

88}
89
90void bagging_demo(bool console, int perc) {
91 array train_images, train_labels;
92 array test_images, test_labels;
93 int num_train, num_test, num_classes;
94
95 // Load mnist data
96 float frac = (float)(perc) / 100.0;
97 setup_mnist<false>(&num_classes, &num_train, &num_test, train_images,
98 test_images, train_labels, test_labels, frac);
99
100 int feature_length = train_images.elements() / num_train;
101 array train_feats = moddims(train_images, feature_length, num_train).T();
102 array test_feats = moddims(test_images, feature_length, num_test).T();
103
104 int num_models = 10;
105 int sample_size = 1000;
106
107 timer::start();
108 // Get the predicted results
109 array res_labels = bagging(train_feats, test_feats, train_labels,
110 num_classes, num_models, sample_size);
111 double test_time = timer::stop();
112
113 // Results
114 printf("Accuracy on testing data: %2.2f\n",
115 accuracy(res_labels, test_labels));
116
117 printf("Prediction time: %4.4f\n", test_time);
118
119 if (false && !console) {
120 display_results<false>(test_images, res_labels, test_labels.T(), 20);
121 }
122}
123
124int main(int argc, char **argv) {
125 int device = argc > 1 ? atoi(argv[1]) : 0;

Callers 1

mainFunction · 0.85

Calls 5

moddimsFunction · 0.85
baggingFunction · 0.85
TMethod · 0.80
accuracyFunction · 0.70
elementsMethod · 0.45

Tested by

no test coverage detected