Self-test implementations.
140 {
143 {0.0, 0.5}, {0.5, 0.5},
144 {1.0, 0.5}, {1.0, 1.0}};
151 assert(model1.predict(sample1, 2) == 2);
152 assert(model1.predict(sample2, 2) == 1);
153 assert(model1.predict(sample3, 2) == 1);
154 assert(model1.predict(sample4, 2) == 2);
158 {0.0, 0.0, 0.0}, {0.25, 0.25, 0.0}, {0.0, 0.5, 0.0}, {0.5, 0.5, 0.0},
159 {1.0, 0.5, 0.0}, {1.0, 1.0, 0.0}, {1.0, 1.0, 1.0}, {1.5, 1.5, 1.0}};
166 assert(model2.predict(sample5, 2) == 2);
167 assert(model2.predict(sample6, 2) == 1);
168 assert(model2.predict(sample7, 2) == 1);
169 assert(model2.predict(sample8, 2) == 3);
173 {4.0}, {5.0}, {6.0}, {7.0}};
180 assert(model3.predict(sample9, 3) == 1);
181 assert(model3.predict(sample10, 3) == 1);
182 assert(model3.predict(sample11, 3) == 2);
183 assert(model3.predict(sample12, 3) == 2);
185}
K-Nearest Neighbors (Knn) class using Euclidean distance as distance metric.
Definition k_nearest_neighbors.cpp:55