def _validate_samples(self, spec, expected_X, expected_y):
        """Validate the float samples returned from the converted scikit KNeighborsClassifier"""
        num_dimensions = (
            spec.kNearestNeighborsClassifier.nearestNeighborsIndex.numberOfDimensions
        )
        for index, sample in enumerate(
            spec.kNearestNeighborsClassifier.nearestNeighborsIndex.floatSamples
        ):
            for dim in range(0, num_dimensions):
                self.assertAlmostEqual(
                    sample.vector[dim], expected_X[index][dim], places=6
                )

        if spec.kNearestNeighborsClassifier.HasField("int64ClassLabels"):
            for index, label in enumerate(
                spec.kNearestNeighborsClassifier.int64ClassLabels.vector
            ):
                self.assertEqual(label, expected_y[index])

        elif spec.kNearestNeighborsClassifier.HasField("stringClassLabels"):
            for index, label in enumerate(
                spec.kNearestNeighborsClassifier.stringClassLabels.vector
            ):
                self.assertEqual(label, expected_y[index])
Validate the float samples returned from the converted scikit KNeighborsClassifier
coremltools/test/sklearn_tests/test_nearest_neighbors_builder.py