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_classification(self):
      from pyspark.mllib.classification import (
          LogisticRegressionWithSGD,
          SVMWithSGD,
          NaiveBayes,
      )
      from pyspark.mllib.tree import DecisionTree
  
      data = [
          LabeledPoint(0.0, self.scipy_matrix(2, {0: 1.0})),
          LabeledPoint(1.0, self.scipy_matrix(2, {1: 1.0})),
          LabeledPoint(0.0, self.scipy_matrix(2, {0: 2.0})),
          LabeledPoint(1.0, self.scipy_matrix(2, {1: 2.0})),
      ]
      rdd = self.sc.parallelize(data)
      features = [p.features for p in data]
  
      lr_model = LogisticRegressionWithSGD.train(rdd)
      self.assertTrue(lr_model.predict(features[0]) <= 0)
      self.assertTrue(lr_model.predict(features[1]) > 0)
      self.assertTrue(lr_model.predict(features[2]) <= 0)
      self.assertTrue(lr_model.predict(features[3]) > 0)
  
      svm_model = SVMWithSGD.train(rdd)
      self.assertTrue(svm_model.predict(features[0]) <= 0)
      self.assertTrue(svm_model.predict(features[1]) > 0)
      self.assertTrue(svm_model.predict(features[2]) <= 0)
      self.assertTrue(svm_model.predict(features[3]) > 0)
  
      nb_model = NaiveBayes.train(rdd)
      self.assertTrue(nb_model.predict(features[0]) <= 0)
      self.assertTrue(nb_model.predict(features[1]) > 0)
      self.assertTrue(nb_model.predict(features[2]) <= 0)
      self.assertTrue(nb_model.predict(features[3]) > 0)
  
      categoricalFeaturesInfo = {0: 3}  # feature 0 has 3 categories
      dt_model = DecisionTree.trainClassifier(
          rdd,
          numClasses=2,
          categoricalFeaturesInfo=categoricalFeaturesInfo,
      )
      self.assertTrue(dt_model.predict(features[0]) <= 0)
      self.assertTrue(dt_model.predict(features[1]) > 0)
      self.assertTrue(dt_model.predict(features[2]) <= 0)
      self.assertTrue(dt_model.predict(features[3]) > 0)
  
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 7 for calling the SciPyTests obj's underlying member method code with example usage: obj.test_classification() without return types