class_docstr: Alternating Least Squares matrix factorization
  
  .. versionadded:: 0.9.0
docstr: Train a matrix factorization model given an RDD of ratings by users
  for a subset of products. The ratings matrix is approximated as the
  product of two lower-rank matrices of a given rank (number of
  features). To solve for these features, ALS is run iteratively with
  a configurable level of parallelism.
  
  .. versionadded:: 0.9.0
  
  Parameters
  ----------
  ratings : :py:class:`pyspark.RDD`
      RDD of `Rating` or (userID, productID, rating) tuple.
  rank : int
      Number of features to use (also referred to as the number of latent factors).
  iterations : int, optional
      Number of iterations of ALS.
      (default: 5)
  lambda\_ : float, optional
      Regularization parameter.
      (default: 0.01)
  blocks : int, optional
      Number of blocks used to parallelize the computation. A value
      of -1 will use an auto-configured number of blocks.
      (default: -1)
  nonnegative : bool, optional
      A value of True will solve least-squares with nonnegativity
      constraints.
      (default: False)
  seed : bool, optional
      Random seed for initial matrix factorization model. A value
      of None will use system time as the seed.
      (default: None)
docstr_tok: ["Train","a","matrix","factorization","model","given","an","RDD","of","ratings","by","users","for","a","subset","of","products",".","The","ratings","matrix","is","approximated","as","the","product","of","two","lower-rank","matrices","of","a","given","rank","(","number","of","features",")",".","To","solve","for","these","features",",","ALS","is","run","iteratively","with","a","configurable","level","of","parallelism",".","..","versionadded",":",":","0.9.0","Parameters","--","--","--","--","--","ratings",":",":","py",":","class",":","`","pyspark.RDD","`","RDD","of","`","Rating","`","or","(","userID",",","productID",",","rating",")","tuple",".","rank",":","int","Number","of","features","to","use","(","also","referred","to","as","the","number","of","latent","factors",")",".","iterations",":","int",",","optional","Number","of","iterations","of","ALS",".","(","default",":","5",")","lambda\\_",":","float",",","optional","Regularization","parameter",".","(","default",":","0.01",")","blocks",":","int",",","optional","Number","of","blocks","used","to","parallelize","the","computation",".","A","value","of","-1","will","use","an","auto-configured","number","of","blocks",".","(","default",":","-1",")","nonnegative",":","bool",",","optional","A","value","of","True","will","solve","least-squares","with","nonnegativity","constraints",".","(","default",":","False",")","seed",":","bool",",","optional","Random","seed","for","initial","matrix","factorization","model",".","A","value","of","None","will","use","system","time","as","the","seed",".","(","default",":","None",")"]
code: def train(
      cls,
      ratings: Union[RDD[Rating], RDD[Tuple[int, int, float]]],
      rank: int,
      iterations: int = 5,
      lambda_: float = 0.01,
      blocks: int = -1,
      nonnegative: bool = False,
      seed: Optional[int] = None,
  ) -> MatrixFactorizationModel:
      """
      Train a matrix factorization model given an RDD of ratings by users
      for a subset of products. The ratings matrix is approximated as the
      product of two lower-rank matrices of a given rank (number of
      features). To solve for these features, ALS is run iteratively with
      a configurable level of parallelism.
  
      .. versionadded:: 0.9.0
  
      Parameters
      ----------
      ratings : :py:class:`pyspark.RDD`
          RDD of `Rating` or (userID, productID, rating) tuple.
      rank : int
          Number of features to use (also referred to as the number of latent factors).
      iterations : int, optional
          Number of iterations of ALS.
          (default: 5)
      lambda\\_ : float, optional
          Regularization parameter.
          (default: 0.01)
      blocks : int, optional
          Number of blocks used to parallelize the computation. A value
          of -1 will use an auto-configured number of blocks.
          (default: -1)
      nonnegative : bool, optional
          A value of True will solve least-squares with nonnegativity
          constraints.
          (default: False)
      seed : bool, optional
          Random seed for initial matrix factorization model. A value
          of None will use system time as the seed.
          (default: None)
      """
      model = callMLlibFunc(
          "trainALSModel",
          cls._prepare(ratings),
          rank,
          iterations,
          lambda_,
          blocks,
          nonnegative,
          seed,
      )
      return MatrixFactorizationModel(model)
  
imports: import array
  import sys
  from typing import Any, List, NamedTuple, Optional, Tuple, Type, Union
  from pyspark import SparkContext, since
  from pyspark.rdd import RDD
  from pyspark.mllib.common import JavaModelWrapper, callMLlibFunc, inherit_doc
  from pyspark.mllib.util import JavaLoader, JavaSaveable
  from pyspark.sql import DataFrame
label_desc: Use image node_id 2 for calling the ALS obj's underlying member method code with example usage: obj.train(cls, ratings, rank, iterations, lambda_, blocks, nonnegative, seed) and returns: MatrixFactorizationModel