MCPcopy Create free account
hub / github.com/apple/coremltools / testKNNValidatorSingleKdTreeIndex

Function testKNNValidatorSingleKdTreeIndex

mlmodel/tests/KNNValidatorTests.cpp:259–291  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

257}
258
259int testKNNValidatorSingleKdTreeIndex() {
260
261 Specification::Model m1;
262
263 KNNValidatorTests::generateInterface(m1);
264
265 auto *knnClassifier = m1.mutable_knearestneighborsclassifier();
266 KNNValidatorTests::setNumberOfNeighbors(knnClassifier, 3, true);
267 knnClassifier->mutable_uniformweighting();
268
269 auto *nnIndex = knnClassifier->mutable_nearestneighborsindex();
270 auto *kdTree = nnIndex->mutable_singlekdtreeindex();
271 nnIndex->mutable_squaredeuclideandistance();
272
273 KNNValidatorTests::addDataPoints(knnClassifier);
274 KNNValidatorTests::addStringLabels(knnClassifier);
275
276 // leaf size = 0 = bad. We're requiring the user to specify a leaf size.
277 Result res = validate<MLModelType_kNearestNeighborsClassifier>(m1);
278 ML_ASSERT_BAD(res);
279
280 // leafSize < 0 = bad
281 kdTree->set_leafsize(-1);
282 res = validate<MLModelType_kNearestNeighborsClassifier>(m1);
283 ML_ASSERT_BAD(res);
284
285 // leafSize > 0 = good
286 kdTree->set_leafsize(30);
287 res = validate<MLModelType_kNearestNeighborsClassifier>(m1);
288 ML_ASSERT_GOOD(res);
289
290 return 0;
291}
292
293int testKNNValidatorNoWeightingScheme() {
294

Callers

nothing calls this directly

Calls 4

generateInterfaceFunction · 0.85
setNumberOfNeighborsFunction · 0.85
addDataPointsFunction · 0.85
addStringLabelsFunction · 0.85

Tested by

no test coverage detected