code: def _daal4py_k_means_fit(
      X,
      nClusters,
      numIterations,
      tol,
      cluster_centers_0,
      n_init,
      verbose,
      random_state,
  ):
      if numIterations < 0:
          raise ValueError("Wrong iterations number")
  
      def is_string(s, target_str):
          return isinstance(s, str) and s == target_str
  
      default_n_init = 10
      if n_init in ["auto", "warn"]:
          if n_init == "warn" and sklearn_check_version("1.2"):
              warnings.warn(
                  "The default value of `n_init` will change from "
                  f"{default_n_init} to 'auto' in 1.4. Set the value of `n_init`"
                  " explicitly to suppress the warning",
                  FutureWarning,
              )
          if is_string(cluster_centers_0, "k-means++"):
              n_init = 1
          else:
              n_init = default_n_init
      X_fptype = getFPType(X)
      abs_tol = _tolerance(X, tol)  # tol is relative tolerance
      is_sparse = sp.issparse(X)
      method = "lloydCSR" if is_sparse else "defaultDense"
      best_inertia, best_cluster_centers = None, None
      best_n_iter = -1
      kmeans_algo = _daal4py_kmeans_compatibility(
          nClusters=nClusters,
          maxIterations=numIterations,
          accuracyThreshold=abs_tol,
          fptype=X_fptype,
          resultsToEvaluate="computeCentroids",
          method=method,
      )
  
      for k in range(n_init):
          (
              deterministic,
              starting_centroids_,
          ) = _daal4py_compute_starting_centroids(
              X,
              X_fptype,
              nClusters,
              cluster_centers_0,
              verbose,
              random_state,
          )
  
          res = kmeans_algo.compute(X, starting_centroids_)
  
          inertia = res.objectiveFunction[0, 0]
          if verbose:
              print(f"Iteration {k}, inertia {inertia}.")
  
          if best_inertia is None or inertia < best_inertia:
              best_cluster_centers = res.centroids
              if n_init > 1:
                  best_cluster_centers = best_cluster_centers.copy()
              best_inertia = inertia
              best_n_iter = int(res.nIterations[0, 0])
          if deterministic and n_init != 1:
              warnings.warn(
                  "Explicit initial center position passed: "
                  "performing only one init in k-means instead of n_init=%d"
                  % n_init,
                  RuntimeWarning,
                  stacklevel=2,
              )
              break
  
      flag_compute = "computeAssignments|computeExactObjectiveFunction"
      best_labels, best_inertia = _daal4py_k_means_predict(
          X, nClusters, best_cluster_centers, flag_compute
      )
  
      distinct_clusters = np.unique(best_labels).size
      if distinct_clusters < nClusters:
          warnings.warn(
              "Number of distinct clusters ({}) found smaller than "
              "n_clusters ({}). Possibly due to duplicate points "
              "in X.".format(distinct_clusters, nClusters),
              ConvergenceWarning,
              stacklevel=2,
          )
          # for passing test case "test_kmeans_warns_less_centers_than_unique_points"
  
      return (
          best_cluster_centers,
          best_labels,
          best_inertia,
          best_n_iter,
      )
  
imports: import numbers
  import warnings
  import numpy
  from scipy import sparse
  from sklearn.cluster import KMeans
  from sklearn.cluster._kmeans import _labels_inertia
  from sklearn.exceptions import ConvergenceWarning
  from sklearn.utils import check_array, check_random_state
  from sklearn.utils._openmp_helpers import _openmp_effective_n_threads
  from sklearn.utils.extmath import row_norms
  from sklearn.utils.sparsefuncs import mean_variance_axis
  from sklearn.utils.validation import _deprecate_positional_args, _num_samples, check_is_fitted
  import daal4py
  from .._device_offload import support_usm_ndarray
  from .._utils import PatchingConditionsChain, control_n_jobs, getFPType, run_with_n_jobs, sklearn_check_version
label_desc: Use image node_id 6 for calling a global function with example usage: _daal4py_k_means_fit(X, nClusters, numIterations, tol, cluster_centers_0, n_init, verbose, random_state) and returns: best_cluster_centers,  best_labels,  best_inertia,  best_n_iter, unknown