code: def _kmeans(obs, guess, thresh=1e-5):
      """ "raw" version of k-means.
  
      Returns
      -------
      code_book
          the lowest distortion codebook found.
      avg_dist
          the average distance a observation is from a code in the book.
          Lower means the code_book matches the data better.
  
      See Also
      --------
      kmeans : wrapper around k-means
  
      Examples
      --------
      Note: not whitened in this example.
  
      >>> from numpy import array
      >>> from scipy.cluster.vq import _kmeans
      >>> features  = array([[ 1.9,2.3],
      ...                    [ 1.5,2.5],
      ...                    [ 0.8,0.6],
      ...                    [ 0.4,1.8],
      ...                    [ 1.0,1.0]])
      >>> book = array((features[0],features[2]))
      >>> _kmeans(features,book)
      (array([[ 1.7       ,  2.4       ],
             [ 0.73333333,  1.13333333]]), 0.40563916697728591)
  
      """
  
      code_book = np.asarray(guess)
      diff = np.inf
      prev_avg_dists = deque([diff], maxlen=2)
      while diff > thresh:
          # compute membership and distances between obs and code_book
          obs_code, distort = vq(obs, code_book, check_finite=False)
          prev_avg_dists.append(distort.mean(axis=-1))
          # recalc code_book as centroids of associated obs
          code_book, has_members = _vq.update_cluster_means(
              obs, obs_code, code_book.shape[0]
          )
          code_book = code_book[has_members]
          diff = prev_avg_dists[0] - prev_avg_dists[1]
  
      return code_book, prev_avg_dists[1]
  
imports: from __future__ import division, print_function, absolute_import
  import warnings
  import numpy
  from collections import deque
  from scipy._lib._util import _asarray_validated
  from scipy._lib.six import xrange
  from scipy.spatial.distance import cdist
  from .None import _vq
label_desc: Use image node_id 4 for calling a global function with example usage: _kmeans(obs, guess, thresh) and returns: code_book,  prev_avg_dists