code: def _build_estimator(self, X=None):
      if not self._estimator_built:
          if self.num_features is None:
              self.num_features = get_num_features(X)
  
          # Reload params from checkpoint if available
          if self._to_be_restored and self.num_features is None:
              self.num_features = read_tensor_in_checkpoint(
                  "num_features", self._to_be_restored
              )
          if self._to_be_restored and self.num_classes is None:
              self.num_classes = read_tensor_in_checkpoint(
                  "num_classes", self._to_be_restored
              )
  
          # Purity checks
          if self.num_features is None:
              raise ValueError("'num_features' cannot be None.")
  
          # Persistent Parameters
          tf.Variable(
              self.num_features, dtype=tf.int32, name="num_features"
          )
  
          self._kmeans = c_ops.KMeans(
              X,
              self.n_clusters,
              initial_clusters=self.init,
              distance_metric=self.distance,
              use_mini_batch=self.use_mini_batch,
          )
          (
              self._all_scores,
              self._cluster_idx,
              self._scores,
              self._cluster_centers_initialized,
              self._cluster_centers_vars,
              self._init_op,
              self._train_op,
          ) = self._kmeans.training_graph()
  
          # fix for cluster_idx being a tuple
          self._cluster_idx = self._cluster_idx[0]
          self.avg_distance = tf.reduce_mean(self._scores)
  
          self._estimator_built = True
          self._init_graph()
  
imports: from __future__ import division, print_function, absolute_import
  from datetime import datetime
  import os
  import math
  import numpy
  import time
  import tensorflow.compat.v1
  from tensorflow.contrib.factorization.python.ops import clustering_ops
  from tensorflow.contrib.tensor_forest.python.ops import data_ops
  from tensorflow.python.ops import state_ops, array_ops, math_ops
  from ...utils import validate_dim, read_tensor_in_checkpoint, prepare_X
  from ...data_utils import get_num_features, get_num_sample
  from ...data_flow import generate_data_tensor
  from ...distances import euclidean, cosine
  from ..base import BaseEstimator
label_desc: Use image node_id 2 for calling the KMeansBase obj's underlying member method code with example usage: obj._build_estimator(X) without return types