class_docstr: Nearest neighbor classifier model. Nearest neighbor classifiers predict the
  class of any observation to be the most common class among the observation's
  closest neighbors.
  
  This model should not be constructed directly. Instead, use
  :func:`turicreate.nearest_neighbor_classifier.create` to create an instance of
  this model.
class_docstr_tok: ["Nearest","neighbor","classifier","model",".","Nearest","neighbor","classifiers","predict","the","class","of","any","observation","to","be","the","most","common","class","among","the","observation's","closest","neighbors",".","This","model","should","not","be","constructed","directly",".","Instead",",","use",":","func",":","`","turicreate.nearest_neighbor_classifier.create","`","to","create","an","instance","of","this","model","."]
docstr: Evaluate the model's predictive accuracy. This is done by predicting the
  target class for instances in a new dataset and comparing to known
  target values.
  
  Parameters
  ----------
  dataset : SFrame
      Dataset of new observations. Must include columns with the same
      names as the target and features used for model training. Additional
      columns are ignored.
  
  metric : str, optional
      Name of the evaluation metric.  Possible values are:
  
      - 'auto': Returns all available metrics.
  
      - 'accuracy': Classification accuracy.
  
      - 'confusion_matrix': An SFrame with counts of possible
        prediction/true label combinations.
  
      - 'roc_curve': An SFrame containing information needed for an roc
        curve (binary classification only).
  
  max_neighbors : int, optional
      Maximum number of neighbors to consider for each point.
  
  radius : float, optional
      Maximum distance from each point to a neighbor in the reference
      dataset.
  
  Returns
  -------
  out : dict
      Evaluation results. The dictionary keys are *accuracy* and
      *confusion_matrix* and *roc_curve* (if applicable).
  
  See also
  --------
  create, predict, predict_topk, classify
  
  Notes
  -----
  - Because the model randomly breaks ties between predicted classes, the
    results of repeated calls to `evaluate` method may differ.
  
  Examples
  --------
  >>> sf_train = turicreate.SFrame({'species': ['cat', 'dog', 'fossa', 'dog'],
  ...                             'height': [9, 25, 20, 23],
  ...                             'weight': [13, 28, 33, 22]})
  >>> m = turicreate.nearest_neighbor_classifier.create(sf, target='species')
  >>> ans = m.evaluate(sf_train, max_neighbors=2,
  ...                  metric='confusion_matrix')
  >>> print ans['confusion_matrix']
  +--------------+-----------------+-------+
  | target_label | predicted_label | count |
  +--------------+-----------------+-------+
  |     cat      |       dog       |   1   |
  |     dog      |       dog       |   2   |
  |    fossa     |       dog       |   1   |
  +--------------+-----------------+-------+
docstr_tok: ["Evaluate","the","model","'s","predictive","accuracy",".","This","is","done","by","predicting","the","target","class","for","instances","in","a","new","dataset","and","comparing","to","known","target","values",".","Parameters","--","--","--","--","--","dataset",":","SFrame","Dataset","of","new","observations",".","Must","include","columns","with","the","same","names","as","the","target","and","features","used","for","model","training",".","Additional","columns","are","ignored",".","metric",":","str",",","optional","Name","of","the","evaluation","metric",".","Possible","values","are",":","-","'auto","'",":","Returns","all","available","metrics",".","-","'accuracy","'",":","Classification","accuracy",".","-","'confusion_matrix","'",":","An","SFrame","with","counts","of","possible","prediction\/true","label","combinations",".","-","'roc_curve","'",":","An","SFrame","containing","information","needed","for","an","roc","curve","(","binary","classification","only",")",".","max_neighbors",":","int",",","optional","Maximum","number","of","neighbors","to","consider","for","each","point",".","radius",":","float",",","optional","Maximum","distance","from","each","point","to","a","neighbor","in","the","reference","dataset",".","Returns","--","--","--","-","out",":","dict","Evaluation","results",".","The","dictionary","keys","are","*","accuracy","*","and","*","confusion_matrix","*","and","*","roc_curve","*","(","if","applicable",")",".","See","also","--","--","--","--","create",",","predict",",","predict_topk",",","classify","Notes","--","--","-","-","Because","the","model","randomly","breaks","ties","between","predicted","classes",",","the","results","of","repeated","calls","to","`","evaluate","`","method","may","differ",".","Examples","--","--","--","--",">",">",">","sf_train","=","turicreate.SFrame","(","{","'species","'",":","[","'cat","'",",","'dog","'",",","'fossa","'",",","'dog","'","]",",","...","'height","'",":","[","9",",","25",",","20",",","23","]",",","...","'weight","'",":","[","13",",","28",",","33",",","22","]","}",")",">",">",">","m","=","turicreate.nearest_neighbor_classifier.create","(","sf",",","target='species","'",")",">",">",">","ans","=","m.evaluate","(","sf_train",",","max_neighbors=2",",","...","metric='confusion_matrix","'",")",">",">",">","print","ans","[","'confusion_matrix","'","]","+","--","--","--","--","--","--","--","+","--","--","--","--","--","--","--","--","-+","--","--","--","-+","|","target_label","|","predicted_label","|","count","|","+","--","--","--","--","--","--","--","+","--","--","--","--","--","--","--","--","-+","--","--","--","-+","|","cat","|","dog","|","1","|","|","dog","|","dog","|","2","|","|","fossa","|","dog","|","1","|","+","--","--","--","--","--","--","--","+","--","--","--","--","--","--","--","--","-+","--","--","--","-+"]
code: def evaluate(
      self, dataset, metric="auto", max_neighbors=10, radius=None
  ):
      """
      Evaluate the model's predictive accuracy. This is done by predicting the
      target class for instances in a new dataset and comparing to known
      target values.
  
      Parameters
      ----------
      dataset : SFrame
          Dataset of new observations. Must include columns with the same
          names as the target and features used for model training. Additional
          columns are ignored.
  
      metric : str, optional
          Name of the evaluation metric.  Possible values are:
  
          - 'auto': Returns all available metrics.
  
          - 'accuracy': Classification accuracy.
  
          - 'confusion_matrix': An SFrame with counts of possible
            prediction/true label combinations.
  
          - 'roc_curve': An SFrame containing information needed for an roc
            curve (binary classification only).
  
      max_neighbors : int, optional
          Maximum number of neighbors to consider for each point.
  
      radius : float, optional
          Maximum distance from each point to a neighbor in the reference
          dataset.
  
      Returns
      -------
      out : dict
          Evaluation results. The dictionary keys are *accuracy* and
          *confusion_matrix* and *roc_curve* (if applicable).
  
      See also
      --------
      create, predict, predict_topk, classify
  
      Notes
      -----
      - Because the model randomly breaks ties between predicted classes, the
        results of repeated calls to `evaluate` method may differ.
  
      Examples
      --------
      >>> sf_train = turicreate.SFrame({'species': ['cat', 'dog', 'fossa', 'dog'],
      ...                             'height': [9, 25, 20, 23],
      ...                             'weight': [13, 28, 33, 22]})
      >>> m = turicreate.nearest_neighbor_classifier.create(sf, target='species')
      >>> ans = m.evaluate(sf_train, max_neighbors=2,
      ...                  metric='confusion_matrix')
      >>> print ans['confusion_matrix']
      +--------------+-----------------+-------+
      | target_label | predicted_label | count |
      +--------------+-----------------+-------+
      |     cat      |       dog       |   1   |
      |     dog      |       dog       |   2   |
      |    fossa     |       dog       |   1   |
      +--------------+-----------------+-------+
      """
  
      ## Validate the metric name
      _raise_error_evaluation_metric_is_valid(
          metric, ["auto", "accuracy", "confusion_matrix", "roc_curve"]
      )
  
      ## Make sure the input dataset has a target column with an appropriate
      #  type.
      target = self.target
      _raise_error_if_column_exists(dataset, target, "dataset", target)
  
      if (
          not dataset[target].dtype == str
          and not dataset[target].dtype == int
      ):
          raise TypeError(
              "The target column of the evaluation dataset must "
              "contain integers or strings."
          )
  
      if self.num_classes != 2:
          if (metric == "roc_curve") or (metric == ["roc_curve"]):
              err_msg = "Currently, ROC curve is not supported for "
              err_msg += "multi-class classification in this model."
              raise _ToolkitError(err_msg)
          else:
              warn_msg = "WARNING: Ignoring `roc_curve`. "
              warn_msg += (
                  "Not supported for multi-class classification."
              )
              print(warn_msg)
  
      ## Compute predictions with the input dataset.
      ystar = self.predict(
          dataset,
          output_type="class",
          max_neighbors=max_neighbors,
          radius=radius,
      )
      ystar_prob = self.predict(
          dataset,
          output_type="probability",
          max_neighbors=max_neighbors,
          radius=radius,
      )
  
      ## Compile accuracy metrics
      results = {}
  
      if metric in ["accuracy", "auto"]:
          results["accuracy"] = _evaluation.accuracy(
              targets=dataset[target], predictions=ystar
          )
  
      if metric in ["confusion_matrix", "auto"]:
          results["confusion_matrix"] = _evaluation.confusion_matrix(
              targets=dataset[target], predictions=ystar
          )
  
      if self.num_classes == 2:
          if metric in ["roc_curve", "auto"]:
              results["roc_curve"] = _evaluation.roc_curve(
                  targets=dataset[target], predictions=ystar_prob
              )
      return results
  
imports: from __future__ import print_function
  from __future__ import division
  from __future__ import absolute_import
  import time
  import copy
  import array
  import logging
  import turicreate
  from turicreate.toolkits._model import CustomModel
  from turicreate.toolkits._internal_utils import _toolkit_repr_print
  from turicreate.toolkits._internal_utils import _raise_error_if_sframe_empty
  from turicreate.toolkits._internal_utils import _raise_error_if_not_sframe
  from turicreate.toolkits._internal_utils import _raise_error_if_column_exists
  from turicreate.toolkits._internal_utils import _raise_error_evaluation_metric_is_valid
  from turicreate.toolkits._main import ToolkitError
  from turicreate.toolkits import evaluation
  from turicreate.toolkits._model import PythonProxy
label_desc: Use image node_id 12 for calling the NearestNeighborClassifier obj's underlying member method code with example usage: obj.evaluate(dataset, metric, max_neighbors, radius) and returns: results