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

Function testEmptyKNNValidationGood

mlmodel/tests/KNNValidatorTests.cpp:364–396  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

362}
363
364int testEmptyKNNValidationGood() {
365
366 Specification::Model m1;
367
368 KNNValidatorTests::generateInterface(m1);
369
370 auto *knnClassifier = m1.mutable_knearestneighborsclassifier();
371 KNNValidatorTests::setNumberOfNeighbors(knnClassifier, 3, true);
372 knnClassifier->mutable_uniformweighting();
373
374 auto *nnIndex = knnClassifier->mutable_nearestneighborsindex();
375 nnIndex->mutable_squaredeuclideandistance();
376 auto *kdTree = nnIndex->mutable_singlekdtreeindex();
377 kdTree->set_leafsize(30);
378
379 // Validation should fail since we are not telling the label type.
380 Result res = validate<MLModelType_kNearestNeighborsClassifier>(m1);
381 ML_ASSERT_BAD(res);
382
383 knnClassifier->set_defaultstringlabel("Default");
384
385 // Validation should pass now.
386 res = validate<MLModelType_kNearestNeighborsClassifier>(m1);
387 ML_ASSERT_GOOD(res);
388
389 knnClassifier->clear_defaultstringlabel();
390
391 // Validation should fail since we are not telling the label type.
392 res = validate<MLModelType_kNearestNeighborsClassifier>(m1);
393 ML_ASSERT_BAD(res);
394
395 return 0;
396}
397
398int testLabelTypeMismatchTest() {
399

Callers

nothing calls this directly

Calls 2

generateInterfaceFunction · 0.85
setNumberOfNeighborsFunction · 0.85

Tested by

no test coverage detected