code: def labels_cost(
      X, centroids, dissim, membship=None, sample_weight=None
  ):
      """Calculate labels and cost function given a matrix of points and
      a list of centroids for the k-modes algorithm.
      """
  
      X = check_array(X)
  
      n_points = X.shape[0]
      cost = 0.0
      labels = np.empty(n_points, dtype=np.uint16)
      for ipoint, curpoint in enumerate(X):
          weight = (
              sample_weight[ipoint] if sample_weight is not None else 1
          )
          diss = dissim(centroids, curpoint, X=X, membship=membship)
          clust = np.argmin(diss)
          labels[ipoint] = clust
          cost += diss[clust] * weight
  
      return labels, cost
  
imports: from collections import defaultdict
  import numpy
  from joblib import Parallel, delayed
  from scipy import sparse
  from sklearn.base import BaseEstimator, ClusterMixin
  from sklearn.utils import check_random_state
  from sklearn.utils.validation import check_array
  from .util import get_max_value_key, encode_features, get_unique_rows, decode_centroids, pandas_to_numpy
  from .util.dissim import matching_dissim, ng_dissim
  from .util.init_methods import init_cao, init_huang
label_desc: Use image node_id 1 for calling a global function with example usage: labels_cost(X, centroids, dissim, membship, sample_weight) and returns: labels,  cost