class_docstr: Unit test class for model creation process under various option values and
  types of input data.
class_docstr_tok: ["Unit","test","class","for","model","creation","process","under","various","option","values","and","types","of","input","data","."]
docstr: Check error trapping and processing of the 'distance' parameter,
  including construction of an automatic composite distance if no distance
  is specified.
docstr_tok: ["Check","error","trapping","and","processing","of","the","'distance","'","parameter",",","including","construction","of","an","automatic","composite","distance","if","no","distance","is","specified","."]
code: def test_distances(self):
      """
      Check error trapping and processing of the 'distance' parameter,
      including construction of an automatic composite distance if no distance
      is specified.
      """
  
      numeric_features = ["int0", "int1", "float0", "float1"]
      array_features = ["array0"]
      string_features = ["str0"]
      dict_features = ["dict0"]
  
      ## Numeric standard distances should work for numeric columns
      for d in [
          "euclidean",
          "squared_euclidean",
          "manhattan",
          "cosine",
          "transformed_dot_product",
      ]:
          try:
              m = tc.nearest_neighbor_classifier.create(
                  self.sf,
                  target="class",
                  features=numeric_features,
                  distance=d,
                  verbose=False,
              )
          except:
              assert False, "Standard distance {} failed.".format(d)
  
      ## Numeric standard distances should work for array columns
      for d in [
          "euclidean",
          "squared_euclidean",
          "manhattan",
          "cosine",
          "transformed_dot_product",
      ]:
          try:
              m = tc.nearest_neighbor_classifier.create(
                  self.sf,
                  target="class",
                  features=array_features,
                  distance=d,
                  verbose=False,
              )
          except:
              assert False, "Standard distance {} failed.".format(d)
  
      ## String standard distances should work.
      for d in ["levenshtein"]:
          try:
              m = tc.nearest_neighbor_classifier.create(
                  self.sf,
                  target="class",
                  features=string_features,
                  distance=d,
                  verbose=False,
              )
          except:
              assert False, "Standard distance {} failed.".format(d)
  
      ## Dictionary standard distances should work.
      for d in [
          "jaccard",
          "weighted_jaccard",
          "cosine",
          "transformed_dot_product",
      ]:
          try:
              m = tc.nearest_neighbor_classifier.create(
                  self.sf,
                  target="class",
                  features=dict_features,
                  distance=d,
                  verbose=False,
              )
          except:
              assert False, "Standard distance {} failed.".format(d)
  
      # Bogus distance strings should not work.
      with self.assertRaises(ValueError):
          m = tc.nearest_neighbor_classifier.create(
              self.sf,
              target="class",
              features=numeric_features,
              distance="fossa",
              verbose=False,
          )
  
      # Nonsensical combinations of feature types and distances should fail.
      with self.assertRaises(ValueError):
          m = tc.nearest_neighbor_classifier.create(
              self.sf,
              target="class",
              features=numeric_features,
              distance="levenshtein",
              verbose=False,
          )
  
      with self.assertRaises(ToolkitError):
          m = tc.nearest_neighbor_classifier.create(
              self.sf,
              target="class",
              features=dict_features,
              distance="levenshtein",
              verbose=False,
          )
  
      with self.assertRaises(ToolkitError):
          m = tc.nearest_neighbor_classifier.create(
              self.sf,
              target="class",
              features=string_features,
              distance="euclidean",
              verbose=False,
          )
  
      # If no distance is specified, the automatic distance construction
      # should kick in and be correct.
      correct_dist = [
          [["str0"], "levenshtein", 1],
          [["str1"], "levenshtein", 1],
          [["dict0"], "weighted_jaccard", 1],
          [
              ["int0", "int1", "float0", "float1", "array0"],
              "euclidean",
              5,
          ],
      ]
  
      m = tc.nearest_neighbor_classifier.create(
          self.sf, target="class", verbose=False
      )
      self.assertEqual(m.distance, correct_dist)
  
imports: from __future__ import print_function
  from __future__ import division
  from __future__ import absolute_import
  import unittest
  import copy
  import array
  import numpy
  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 KnnClassifierCreateTest obj's underlying member method code with example usage: obj.test_distances() without return types