class_docstr: kmeans1d tests
code: def test_weights_vs_repetition(self):
      x = [10, 24, 16, 12, 20]
      w = [3, 1, 4, 2, 3]
      k = 2
  
      # Unweighted
      u_clusters, _ = cluster(x, k)
      self.assertEqual(u_clusters, [0, 1, 0, 0, 1])
  
      # Weighted: different than unweighted
      w_clusters, w_centroids = cluster(x, k, weights=w)
      w_ssd = compute_inertial(x, w, w_clusters, w_centroids)
      self.assertEqual(w_clusters, [0, 1, 1, 0, 1])
      self.assertEqual(w_centroids, [10.8, 18.5])
      self.assertEqual(w_ssd, 66.8)
  
      # Repeated values: same as weighted
      r_x = [xi for xi, n in zip(x, w) for _ in range(n)]
      self.assertEqual(len(r_x), sum(w))
      r_clusters, r_centroids = cluster(r_x, k)
      r_ssd = compute_inertial(
          r_x, [1] * len(r_x), r_clusters, r_centroids
      )
      self.assertEqual(r_centroids, w_centroids)
      self.assertEqual(r_ssd, w_ssd)
  
file_path: coremltools/deps/kmeans1d/tests/test_kmeans1d.py
imports: import unittest
  from kmeans1d import cluster
label_desc: Use image node_id 3 for calling the TestKmeans1D obj's underlying member method code with example usage: obj.test_weights_vs_repetition() without return types