class_docstr: Learning algorithm for a random forest model for classification or
  regression.
  
  .. versionadded:: 1.2.0
class_docstr_tok: ["Learning","algorithm","for","a","random","forest","model","for","classification","or","regression",".","..","versionadded",":",":","1.2.0"]
docstr: Train a random forest model for binary or multiclass
  classification.
  
  .. versionadded:: 1.2.0
  
  Parameters
  ----------
  data : :py:class:`pyspark.RDD`
      Training dataset: RDD of LabeledPoint. Labels should take values
      {0, 1, ..., numClasses-1}.
  numClasses : int
      Number of classes for classification.
  categoricalFeaturesInfo : dict
      Map storing arity of categorical features. An entry (n -> k)
      indicates that feature n is categorical with k categories
      indexed from 0: {0, 1, ..., k-1}.
  numTrees : int
      Number of trees in the random forest.
  featureSubsetStrategy : str, optional
      Number of features to consider for splits at each node.
      Supported values: "auto", "all", "sqrt", "log2", "onethird".
      If "auto" is set, this parameter is set based on numTrees:
      if numTrees == 1, set to "all";
      if numTrees > 1 (forest) set to "sqrt".
      (default: "auto")
  impurity : str, optional
      Criterion used for information gain calculation.
      Supported values: "gini" or "entropy".
      (default: "gini")
  maxDepth : int, optional
      Maximum depth of tree (e.g. depth 0 means 1 leaf node, depth 1
      means 1 internal node + 2 leaf nodes).
      (default: 4)
  maxBins : int, optional
      Maximum number of bins used for splitting features.
      (default: 32)
  seed : int, Optional
      Random seed for bootstrapping and choosing feature subsets.
      Set as None to generate seed based on system time.
      (default: None)
  
  Returns
  -------
  :py:class:`RandomForestModel`
      that can be used for prediction.
  
  Examples
  --------
  >>> from pyspark.mllib.regression import LabeledPoint
  >>> from pyspark.mllib.tree import RandomForest
  >>>
  >>> data = [
  ...     LabeledPoint(0.0, [0.0]),
  ...     LabeledPoint(0.0, [1.0]),
  ...     LabeledPoint(1.0, [2.0]),
  ...     LabeledPoint(1.0, [3.0])
  ... ]
  >>> model = RandomForest.trainClassifier(sc.parallelize(data), 2, {}, 3, seed=42)
  >>> model.numTrees()
  3
  >>> model.totalNumNodes()
  7
  >>> print(model)
  TreeEnsembleModel classifier with 3 trees
  >>> print(model.toDebugString())
  TreeEnsembleModel classifier with 3 trees
    Tree 0:
      Predict: 1.0
    Tree 1:
      If (feature 0 <= 1.5)
       Predict: 0.0
      Else (feature 0 > 1.5)
       Predict: 1.0
    Tree 2:
      If (feature 0 <= 1.5)
       Predict: 0.0
      Else (feature 0 > 1.5)
       Predict: 1.0
  >>> model.predict([2.0])
  1.0
  >>> model.predict([0.0])
  0.0
  >>> rdd = sc.parallelize([[3.0], [1.0]])
  >>> model.predict(rdd).collect()
  [1.0, 0.0]
docstr_tok: ["Train","a","random","forest","model","for","binary","or","multiclass","classification",".","..","versionadded",":",":","1.2.0","Parameters","--","--","--","--","--","data",":",":","py",":","class",":","`","pyspark.RDD","`","Training","dataset",":","RDD","of","LabeledPoint",".","Labels","should","take","values","{","0",",","1",",","...",",","numClasses-1","}",".","numClasses",":","int","Number","of","classes","for","classification",".","categoricalFeaturesInfo",":","dict","Map","storing","arity","of","categorical","features",".","An","entry","(","n","-",">","k",")","indicates","that","feature","n","is","categorical","with","k","categories","indexed","from","0",":","{","0",",","1",",","...",",","k-1","}",".","numTrees",":","int","Number","of","trees","in","the","random","forest",".","featureSubsetStrategy",":","str",",","optional","Number","of","features","to","consider","for","splits","at","each","node",".","Supported","values",":","``","auto","''",",","``","all","''",",","``","sqrt","''",",","``","log2","''",",","``","onethird","''",".","If","``","auto","''","is","set",",","this","parameter","is","set","based","on","numTrees",":","if","numTrees","==","1",",","set","to","``","all","''",";","if","numTrees",">","1","(","forest",")","set","to","``","sqrt","''",".","(","default",":","``","auto","''",")","impurity",":","str",",","optional","Criterion","used","for","information","gain","calculation",".","Supported","values",":","``","gini","''","or","``","entropy","''",".","(","default",":","``","gini","''",")","maxDepth",":","int",",","optional","Maximum","depth","of","tree","(","e.g",".","depth","0","means","1","leaf","node",",","depth","1","means","1","internal","node","+","2","leaf","nodes",")",".","(","default",":","4",")","maxBins",":","int",",","optional","Maximum","number","of","bins","used","for","splitting","features",".","(","default",":","32",")","seed",":","int",",","Optional","Random","seed","for","bootstrapping","and","choosing","feature","subsets",".","Set","as","None","to","generate","seed","based","on","system","time",".","(","default",":","None",")","Returns","--","--","--","-",":","py",":","class",":","`","RandomForestModel","`","that","can","be","used","for","prediction",".","Examples","--","--","--","--",">",">",">","from","pyspark.mllib.regression","import","LabeledPoint",">",">",">","from","pyspark.mllib.tree","import","RandomForest",">",">",">",">",">",">","data","=","[","...","LabeledPoint","(","0.0",",","[","0.0","]",")",",","...","LabeledPoint","(","0.0",",","[","1.0","]",")",",","...","LabeledPoint","(","1.0",",","[","2.0","]",")",",","...","LabeledPoint","(","1.0",",","[","3.0","]",")","...","]",">",">",">","model","=","RandomForest.trainClassifier","(","sc.parallelize","(","data",")",",","2",",","{","}",",","3",",","seed=42",")",">",">",">","model.numTrees","(",")","3",">",">",">","model.totalNumNodes","(",")","7",">",">",">","print","(","model",")","TreeEnsembleModel","classifier","with","3","trees",">",">",">","print","(","model.toDebugString","(",")",")","TreeEnsembleModel","classifier","with","3","trees","Tree","0",":","Predict",":","1.0","Tree","1",":","If","(","feature","0","<","=","1.5",")","Predict",":","0.0","Else","(","feature","0",">","1.5",")","Predict",":","1.0","Tree","2",":","If","(","feature","0","<","=","1.5",")","Predict",":","0.0","Else","(","feature","0",">","1.5",")","Predict",":","1.0",">",">",">","model.predict","(","[","2.0","]",")","1.0",">",">",">","model.predict","(","[","0.0","]",")","0.0",">",">",">","rdd","=","sc.parallelize","(","[","[","3.0","]",",","[","1.0","]","]",")",">",">",">","model.predict","(","rdd",")",".collect","(",")","[","1.0",",","0.0","]"]
code: def trainClassifier(
      cls,
      data: RDD[LabeledPoint],
      numClasses: int,
      categoricalFeaturesInfo: Dict[int, int],
      numTrees: int,
      featureSubsetStrategy: str = "auto",
      impurity: str = "gini",
      maxDepth: int = 4,
      maxBins: int = 32,
      seed: Optional[int] = None,
  ) -> RandomForestModel:
      """
      Train a random forest model for binary or multiclass
      classification.
  
      .. versionadded:: 1.2.0
  
      Parameters
      ----------
      data : :py:class:`pyspark.RDD`
          Training dataset: RDD of LabeledPoint. Labels should take values
          {0, 1, ..., numClasses-1}.
      numClasses : int
          Number of classes for classification.
      categoricalFeaturesInfo : dict
          Map storing arity of categorical features. An entry (n -> k)
          indicates that feature n is categorical with k categories
          indexed from 0: {0, 1, ..., k-1}.
      numTrees : int
          Number of trees in the random forest.
      featureSubsetStrategy : str, optional
          Number of features to consider for splits at each node.
          Supported values: "auto", "all", "sqrt", "log2", "onethird".
          If "auto" is set, this parameter is set based on numTrees:
          if numTrees == 1, set to "all";
          if numTrees > 1 (forest) set to "sqrt".
          (default: "auto")
      impurity : str, optional
          Criterion used for information gain calculation.
          Supported values: "gini" or "entropy".
          (default: "gini")
      maxDepth : int, optional
          Maximum depth of tree (e.g. depth 0 means 1 leaf node, depth 1
          means 1 internal node + 2 leaf nodes).
          (default: 4)
      maxBins : int, optional
          Maximum number of bins used for splitting features.
          (default: 32)
      seed : int, Optional
          Random seed for bootstrapping and choosing feature subsets.
          Set as None to generate seed based on system time.
          (default: None)
  
      Returns
      -------
      :py:class:`RandomForestModel`
          that can be used for prediction.
  
      Examples
      --------
      >>> from pyspark.mllib.regression import LabeledPoint
      >>> from pyspark.mllib.tree import RandomForest
      >>>
      >>> data = [
      ...     LabeledPoint(0.0, [0.0]),
      ...     LabeledPoint(0.0, [1.0]),
      ...     LabeledPoint(1.0, [2.0]),
      ...     LabeledPoint(1.0, [3.0])
      ... ]
      >>> model = RandomForest.trainClassifier(sc.parallelize(data), 2, {}, 3, seed=42)
      >>> model.numTrees()
      3
      >>> model.totalNumNodes()
      7
      >>> print(model)
      TreeEnsembleModel classifier with 3 trees
      >>> print(model.toDebugString())
      TreeEnsembleModel classifier with 3 trees
        Tree 0:
          Predict: 1.0
        Tree 1:
          If (feature 0 <= 1.5)
           Predict: 0.0
          Else (feature 0 > 1.5)
           Predict: 1.0
        Tree 2:
          If (feature 0 <= 1.5)
           Predict: 0.0
          Else (feature 0 > 1.5)
           Predict: 1.0
      >>> model.predict([2.0])
      1.0
      >>> model.predict([0.0])
      0.0
      >>> rdd = sc.parallelize([[3.0], [1.0]])
      >>> model.predict(rdd).collect()
      [1.0, 0.0]
      """
      return cls._train(
          data,
          "classification",
          numClasses,
          categoricalFeaturesInfo,
          numTrees,
          featureSubsetStrategy,
          impurity,
          maxDepth,
          maxBins,
          seed,
      )
  
imports: import sys
  import random
  from pyspark import RDD, since
  from pyspark.mllib.common import callMLlibFunc, inherit_doc, JavaModelWrapper
  from pyspark.mllib.linalg import _convert_to_vector
  from pyspark.mllib.regression import LabeledPoint
  from pyspark.mllib.util import JavaLoader, JavaSaveable
  from typing import Dict, Optional, Tuple, Union, overload, TYPE_CHECKING
  from pyspark.rdd import RDD
label_desc: Use image node_id 2 for calling the RandomForest obj's underlying member method code with example usage: obj.trainClassifier(cls, data, numClasses, categoricalFeaturesInfo, numTrees, featureSubsetStrategy, impurity, maxDepth, maxBins, seed) and returns: cls