def test_conversion_distance_function_good(self):
        """Tests conversion of a scikit KNeighborsClassifier with a valid distance metric."""
        scikit_model = KNeighborsClassifier(algorithm="brute", metric="euclidean")
        scikit_model.fit(self.iris_X, self.iris_y)
        coreml_model = sklearn.convert(scikit_model, "single_input", "single_output")
        coreml_spec = coreml_model.get_spec()
        self.assertIsNotNone(coreml_spec)
        self.assertTrue(
            coreml_spec.kNearestNeighborsClassifier.nearestNeighborsIndex.HasField(
                "squaredEuclideanDistance"
            )
        )

        # Minkowski metric with p=2 is equivalent to the squared Euclidean distance
        scikit_model = KNeighborsClassifier(algorithm="brute", metric="minkowski", p=2)
        scikit_model.fit(self.iris_X, self.iris_y)
        coreml_spec = coreml_model.get_spec()
        self.assertIsNotNone(coreml_spec)
        self.assertTrue(
            coreml_spec.kNearestNeighborsClassifier.nearestNeighborsIndex.HasField(
                "squaredEuclideanDistance"
            )
        )
Tests conversion of a scikit KNeighborsClassifier with a valid distance metric.
coremltools/test/sklearn_tests/test_k_neighbors_classifier.py