class_docstr: Scalable KMeans for clustering
  
  Parameters
  ----------
  n_clusters : int, default 8
      Number of clusters to end up with
  init : {'k-means||', 'k-means++' or ndarray}
      Method for center initialization, defaults to 'k-means||'.
  
      'k-means||' : selects the the gg
  
      'k-means++' : selects the initial cluster centers in a smart way
      to speed up convergence. Uses scikit-learn's implementation.
  
      .. warning::
  
         If using ``'k-means++'``, the entire dataset will be read into
         memory at once.
  
      An array of shape (n_clusters, n_features) can be used to give
      an explicit starting point
  
  oversampling_factor : int, default 2
      Oversampling factor for use in the ``k-means||`` algorithm.
  
  max_iter : int
      Maximum number EM iterations to attempt.
  
  init_max_iter : int
      Number of iterations for init step.
  
  tol : float
      Relative tolerance with regards to inertia to declare convergence
  
  algorithm : 'full'
      The algorithm to use for the EM step. Only "full" (LLoyd's algorithm)
      is allowed.
  
  random_state : int, RandomState instance or None, optional, default: None
      If int, random_state is the seed used by the random number generator;
      If RandomState instance, random_state is the random number generator;
      If None, the random number generator is the RandomState instance used
      by `np.random`.
  
  n_init : 'auto' or int, default=10
      Number of times the k-means algorithm will be run with different
      centroid seeds. The final results will be the best output of
      n_init consecutive runs in terms of inertia.
      When `n_init='auto'`, the number of runs will be 10 if using
      `init='random'`, and 1 if using `init='kmeans++'`.
      .. versionadded:: 1.2
         Added 'auto' option for `n_init`.
      .. versionchanged:: 1.4
         Default value for `n_init` will change from 10 to `'auto'` in version 1.4.
  
  Attributes
  ----------
  cluster_centers_ : np.ndarray [n_clusters, n_features]
      A NumPy array with the cluster centers
  
  labels_ : da.array [n_samples,]
      A dask array with the index position in ``cluster_centers_`` this
      sample belongs to.
  
  inertia_ : float
      Sum of distances of samples to their closest cluster center.
  
  n_iter_ : int
      Number of EM steps to reach convergence
  
  References
  ----------
  - Scalable K-Means++, 2012
    Bahman Bahmani, Benjamin Moseley, Andrea Vattani, Ravi Kumar,
    Sergei Vassilvitskii
    https://arxiv.org/abs/1203.6402
  
  See Also
  --------
  sklearn.cluster.MiniBatchKMeans
  sklearn.cluster.KMeans
  
  Notes
  -----
  This class implements a parallel and distributed version of k-Means.
  
  **Initialization with k-means||**
  
  The default initializer for ``KMeans`` is ``k-means||``, compared to
  ``k-means++`` from scikit-learn. This is the algorithm described in
  *Scalable K-Means++ (2012)*.
  
  ``k-means||`` is designed to work well in a distributed environment. It's a
  variant of k-means++ that's designed to work in parallel (k-means++ is
  inherently sequential). Currently, the ``k-means||`` implementation here is
  slower than scikit-learn's ``k-means++`` if your entire dataset fits in
  memory on a single machine. If that's the case, consider using
  ``init='k-means++'``.
  
  **Parallel Lloyd's Algorithm**
  
  LLoyd's Algorithm (the default Expectation Maximization algorithm used in
  scikit-learn) is naturally parallelizable. In naive benchmarks, the
  implementation here achieves 2-3x speedups over scikit-learn.
  
  Both the initialization step and the EM steps make multiple passes over the
  data. If possible, persist your dask collections in (distributed) memory
  before running ``.fit``.
class_docstr_tok: ["Scalable","KMeans","for","clustering","Parameters","--","--","--","--","--","n_clusters",":","int",",","default","8","Number","of","clusters","to","end","up","with","init",":","{","'","k-means||","'",",","'","k-means++","'","or","ndarray","}","Method","for","center","initialization",",","defaults","to","'","k-means||","'",".","'","k-means||","'",":","selects","the","the","gg","'","k-means++","'",":","selects","the","initial","cluster","centers","in","a","smart","way","to","speed","up","convergence",".","Uses","scikit-learn","'s","implementation",".","..","warning",":",":","If","using","``","'","k-means++","'","``",",","the","entire","dataset","will","be","read","into","memory","at","once",".","An","array","of","shape","(","n_clusters",",","n_features",")","can","be","used","to","give","an","explicit","starting","point","oversampling_factor",":","int",",","default","2","Oversampling","factor","for","use","in","the","``","k-means||","``","algorithm",".","max_iter",":","int","Maximum","number","EM","iterations","to","attempt",".","init_max_iter",":","int","Number","of","iterations","for","init","step",".","tol",":","float","Relative","tolerance","with","regards","to","inertia","to","declare","convergence","algorithm",":","'full'","The","algorithm","to","use","for","the","EM","step",".","Only","``","full","''","(","LLoyd","'s","algorithm",")","is","allowed",".","random_state",":","int",",","RandomState","instance","or","None",",","optional",",","default",":","None","If","int",",","random_state","is","the","seed","used","by","the","random","number","generator",";","If","RandomState","instance",",","random_state","is","the","random","number","generator",";","If","None",",","the","random","number","generator","is","the","RandomState","instance","used","by","`","np.random","`",".","n_init",":","'auto","'","or","int",",","default=10","Number","of","times","the","k-means","algorithm","will","be","run","with","different","centroid","seeds",".","The","final","results","will","be","the","best","output","of","n_init","consecutive","runs","in","terms","of","inertia",".","When","`","n_init='auto","'","`",",","the","number","of","runs","will","be","10","if","using","`","init='random","'","`",",","and","1","if","using","`","init='kmeans++","'","`",".","..","versionadded",":",":","1.2","Added","'auto","'","option","for","`","n_init","`",".","..","versionchanged",":",":","1.4","Default","value","for","`","n_init","`","will","change","from","10","to","`","'auto","'","`","in","version","1.4",".","Attributes","--","--","--","--","--","cluster_centers_",":","np.ndarray","[","n_clusters",",","n_features","]","A","NumPy","array","with","the","cluster","centers","labels_",":","da.array","[","n_samples",",","]","A","dask","array","with","the","index","position","in","``","cluster_centers_","``","this","sample","belongs","to",".","inertia_",":","float","Sum","of","distances","of","samples","to","their","closest","cluster","center",".","n_iter_",":","int","Number","of","EM","steps","to","reach","convergence","References","--","--","--","--","--","-","Scalable","K-Means++",",","2012","Bahman","Bahmani",",","Benjamin","Moseley",",","Andrea","Vattani",",","Ravi","Kumar",",","Sergei","Vassilvitskii","https",":","\/\/arxiv.org\/abs\/1203.6402","See","Also","--","--","--","--","sklearn.cluster.MiniBatchKMeans","sklearn.cluster.KMeans","Notes","--","--","-","This","class","implements","a","parallel","and","distributed","version","of","k-Means",".","*","*","Initialization","with","k-means||","*","*","The","default","initializer","for","``","KMeans","``","is","``","k-means||","``",",","compared","to","``","k-means++","``","from","scikit-learn",".","This","is","the","algorithm","described","in","*","Scalable","K-Means++","(","2012",")","*",".","``","k-means||","``","is","designed","to","work","well","in","a","distributed","environment",".","It","'s","a","variant","of","k-means++","that","'s","designed","to","work","in","parallel","(","k-means++","is","inherently","sequential",")",".","Currently",",","the","``","k-means||","``","implementation","here","is","slower","than","scikit-learn","'s","``","k-means++","``","if","your","entire","dataset","fits","in","memory","on","a","single","machine",".","If","that","'s","the","case",",","consider","using","``","init=","'","k-means++","'","``",".","*","*","Parallel","Lloyd","'s","Algorithm","*","*","LLoyd","'s","Algorithm","(","the","default","Expectation","Maximization","algorithm","used","in","scikit-learn",")","is","naturally","parallelizable",".","In","naive","benchmarks",",","the","implementation","here","achieves","2-3x","speedups","over","scikit-learn",".","Both","the","initialization","step","and","the","EM","steps","make","multiple","passes","over","the","data",".","If","possible",",","persist","your","dask","collections","in","(","distributed",")","memory","before","running","``",".fit","``","."]
code: def _check_array(self, X):
      if isinstance(X, pd.DataFrame):
          X = X.values
  
      if isinstance(X, dd.DataFrame):
          X = X.to_dask_array(lengths=True)
  
      X = check_array(
          X,
          accept_dask_dataframe=False,
          accept_unknown_chunks=False,
          accept_sparse=False,
          remove_zero_chunks=True,
      )
  
      if X.dtype == "int32":
          X = X.astype("float32")
      elif X.dtype == "int64":
          X = X.astype("float64")
  
      if isinstance(X, np.ndarray):
          X = da.from_array(
              X, chunks=(max(1, len(X) // cpu_count()), X.shape[-1])
          )
  
      bad = (da.isnull(X).any(), da.isinf(X).any())
      if any(*compute(bad)):
          msg = (
              "Input contains NaN, infinity or a value too large for "
              "dtype('float64')."
          )
          raise ValueError(msg)
      return X
  
imports: import logging
  from multiprocessing import cpu_count
  from numbers import Integral
  import dask.array
  import dask.dataframe
  import numpy
  import pandas
  import sklearn.cluster
  from dask import compute
  from sklearn.base import BaseEstimator, TransformerMixin
  from sklearn.utils.extmath import squared_norm
  from sklearn.utils.validation import check_is_fitted
  from .._compat import blockwise
  from .._utils import draw_seed
  from ..metrics import euclidean_distances, pairwise_distances, pairwise_distances_argmin_min
  from ..utils import _timed, _timer, check_array, row_norms
  from ._compat import _kmeans_plusplus
  import numba
label_desc: Use image node_id 2 for calling the KMeans obj's underlying member method code with example usage: obj._check_array(X) and returns: X