code: def compute_bench(samples_range, features_range):
      it = 0
      results = defaultdict(lambda: [])
      chunk = 100
  
      max_it = len(samples_range) * len(features_range)
      for n_samples in samples_range:
          for n_features in features_range:
              it += 1
              print("==============================")
              print("Iteration %03d of %03d" % (it, max_it))
              print("==============================")
              print()
              data = nr.randint(-50, 51, (n_samples, n_features))
  
              print("K-Means")
              tstart = time()
              kmeans = KMeans(init="k-means++", n_clusters=10).fit(data)
  
              delta = time() - tstart
              print("Speed: %0.3fs" % delta)
              print("Inertia: %0.5f" % kmeans.inertia_)
              print()
  
              results["kmeans_speed"].append(delta)
              results["kmeans_quality"].append(kmeans.inertia_)
  
              print("Fast K-Means")
              # let's prepare the data in small chunks
              mbkmeans = MiniBatchKMeans(
                  init="k-means++", n_clusters=10, batch_size=chunk
              )
              tstart = time()
              mbkmeans.fit(data)
              delta = time() - tstart
              print("Speed: %0.3fs" % delta)
              print("Inertia: %f" % mbkmeans.inertia_)
              print()
              print()
  
              results["MiniBatchKMeans Speed"].append(delta)
              results["MiniBatchKMeans Quality"].append(
                  mbkmeans.inertia_
              )
  
      return results
  
imports: from collections import defaultdict
  from time import time
  import numpy
  from numpy import random
  from sklearn.cluster import KMeans, MiniBatchKMeans
label_desc: Use image node_id 1 for calling a global function with example usage: compute_bench(samples_range, features_range) and returns: results