class_docstr: Unit test class for testing scikit-learn converter.
class_docstr_tok: ["Unit","test","class","for","testing","scikit-learn","converter","."]
docstr: Tests conversion of a scikit KNeighborsClassifier using the brute force algorithm.
docstr_tok: ["Tests","conversion","of","a","scikit","KNeighborsClassifier","using","the","brute","force","algorithm","."]
code: def test_conversion_kd_tree_algorithm(self):
      """Tests conversion of a scikit KNeighborsClassifier using the brute force algorithm."""
      test_leaf_size = 23
      test_n_neighbors = 42
      scikit_model = KNeighborsClassifier(
          algorithm="kd_tree",
          leaf_size=test_leaf_size,
          n_neighbors=test_n_neighbors,
      )
      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,
          test_n_neighbors,
      )
      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(
              "singleKdTreeIndex"
          )
      )
      self.assertEqual(
          test_leaf_size,
          coreml_spec.kNearestNeighborsClassifier.nearestNeighborsIndex.singleKdTreeIndex.leafSize,
      )
      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)
  
file_path: turicreate/src/external/coremltools_wrap/coremltools/coremltools/test/sklearn_tests/test_k_neighbors_classifier.py
imports: import unittest
  import numpy
  from scipy import sparse
  from coremltools._deps import _HAS_SKLEARN
label_desc: Use image node_id 4 for calling the KNeighborsClassifierScikitTest obj's underlying member method code with example usage: obj.test_conversion_kd_tree_algorithm() without return types