def test_conversion_brute_algorithm(self):
        """Tests conversion of a scikit KNeighborsClassifier using the brute force algorithm."""
        scikit_model = KNeighborsClassifier(algorithm="brute", n_neighbors=42)
        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.HasField("kNearestNeighborsClassifier"))
        self.assertEqual(
            coreml_spec.kNearestNeighborsClassifier.numberOfNeighbors.defaultValue, 42
        )
        self.assertEqual(
            coreml_spec.kNearestNeighborsClassifier.numberOfNeighbors.range.minValue, 1
        )
        self.assertEqual(
            coreml_spec.kNearestNeighborsClassifier.numberOfNeighbors.range.maxValue,
            len(self.iris_X),
        )
        self.assertTrue(
            coreml_spec.kNearestNeighborsClassifier.HasField("uniformWeighting")
        )
        self.assertEqual(
            coreml_spec.kNearestNeighborsClassifier.nearestNeighborsIndex.numberOfDimensions,
            len(self.iris_X[0]),
        )
        self.assertTrue(
            coreml_spec.kNearestNeighborsClassifier.nearestNeighborsIndex.HasField(
                "linearIndex"
            )
        )
        self.assertTrue(
            coreml_spec.kNearestNeighborsClassifier.nearestNeighborsIndex.HasField(
                "squaredEuclideanDistance"
            )
        )

        self.validate_labels(coreml_spec, self.iris_y)
        self.validate_float_samples(coreml_spec, self.iris_X)
Tests conversion of a scikit KNeighborsClassifier using the brute force algorithm.
coremltools/test/sklearn_tests/test_k_neighbors_classifier.py