class_docstr: Test both vector operations and MLlib algorithms with SciPy sparse matrices,
  if SciPy is available.
class_docstr_tok: ["Test","both","vector","operations","and","MLlib","algorithms","with","SciPy","sparse","matrices",",","if","SciPy","is","available","."]
code: def test_clustering(self):
      from pyspark.mllib.clustering import KMeans
  
      data = [
          self.scipy_matrix(3, {1: 1.0}),
          self.scipy_matrix(3, {1: 1.1}),
          self.scipy_matrix(3, {2: 1.0}),
          self.scipy_matrix(3, {2: 1.1}),
      ]
      clusters = KMeans.train(
          self.sc.parallelize(data), 2, initializationMode="k-means||"
      )
      self.assertEqual(
          clusters.predict(data[0]), clusters.predict(data[1])
      )
      self.assertEqual(
          clusters.predict(data[2]), clusters.predict(data[3])
      )
  
imports: import array
  import unittest
  from numpy import array, array_equal, zeros, arange, tile, ones, inf
  import pyspark.ml.linalg
  from pyspark.serializers import CPickleSerializer
  from pyspark.mllib.linalg import Vector, SparseVector, DenseVector, VectorUDT, _convert_to_vector, DenseMatrix, SparseMatrix, Vectors, Matrices, MatrixUDT
  from pyspark.mllib.linalg.distributed import RowMatrix, IndexedRowMatrix, IndexedRow
  from pyspark.mllib.regression import LabeledPoint
  from pyspark.sql import Row
  from pyspark.testing.mllibutils import MLlibTestCase
  from pyspark.testing.utils import have_scipy
label_desc: Use image node_id 6 for calling the SciPyTests obj's underlying member method code with example usage: obj.test_clustering() without return types