class_docstr: Unit test class for the correctness or plausibility of Kmeans clustering
  results.
docstr: Test correctness of predictions on new data, by comparing to nearest
  neighbors search results. Note that this implicitly checks that integer
  features are correctly cast as floats in the predict method.
code: def test_predictions(self):
      """
      Test correctness of predictions on new data, by comparing to nearest
      neighbors search results. Note that this implicitly checks that integer
      features are correctly cast as floats in the predict method.
      """
      sf_train = self.sf[:-10]
      sf_predict = self.sf[-10:]
  
      kmeans = tc.kmeans.create(sf_train, num_clusters=3, verbose=False)
      sf_train_copy = copy.copy(sf_train)
  
      ## Check internal consistency - each training point's closest center
      #  should be the one for the assigned cluster. Also check that the
      #  input SFrame isn't mutated.
      yhat = kmeans.predict(sf_train)
  
      assert_sframe_equal(sf_train, sf_train_copy)
      self.assertTrue((yhat == kmeans.cluster_id["cluster_id"]).all())
  
      ## Check internal consistency for prediction distances.
      yhat_dists = kmeans.predict(sf_train, output_type="distance")
      assert_allclose(
          yhat_dists, kmeans.cluster_id["distance"], rtol=1e-6
      )
  
      ## Check consistency with nearest neighbors.
  
      # get the predictions from the model and combine into a single SFrame.
      ystar_labels = kmeans.predict(
          sf_predict, output_type="cluster_id"
      )
      ystar_dists = kmeans.predict(sf_predict, output_type="distance")
  
      ystar = tc.SFrame(
          {"cluster_id": ystar_labels, "distance": ystar_dists}
      )
      ystar = ystar.add_row_number("row_id")
  
      # convert type of predictions to floats so they match the types of the
      # centers in the nearest neighbors model.
      coltype_map = {
          k: v
          for k, v in zip(
              sf_predict.column_names(), sf_predict.column_types()
          )
      }
      for ftr in coltype_map.keys():
          if coltype_map[ftr] is int:
              sf_predict[ftr] = sf_predict[ftr].astype(float)
  
      knn_model = tc.nearest_neighbors.create(
          kmeans.cluster_info,
          features=kmeans.features,
          distance="euclidean",
          method="ball_tree",
      )
      knn_dists = knn_model.query(sf_predict, k=1, radius=None)
  
      assert_sframe_equal(
          ystar[["row_id", "cluster_id"]],
          knn_dists[["query_label", "reference_label"]],
          check_column_names=False,
      )
  
      assert_allclose(
          ystar["distance"], knn_dists["distance"], rtol=1e-6
      )
  
imports: from __future__ import print_function
  from __future__ import division
  from __future__ import absolute_import
  import unittest
  import copy
  import numpy
  from numpy.testing import assert_allclose
  import turicreate
  from .None import util
  from turicreate.util import _assert_sframe_equal
  from turicreate.toolkits._main import ToolkitError
  import sys
label_desc: Use image node_id 4 for calling the KmeansClusterTest obj's underlying member method code with example usage: obj.test_predictions() without return types