Packages

  • package root
    Definition Classes
    root
  • package org
    Definition Classes
    root
  • package apache
    Definition Classes
    org
  • package spark

    Core Spark functionality.

    Core Spark functionality. org.apache.spark.SparkContext serves as the main entry point to Spark, while org.apache.spark.rdd.RDD is the data type representing a distributed collection, and provides most parallel operations.

    In addition, org.apache.spark.rdd.PairRDDFunctions contains operations available only on RDDs of key-value pairs, such as groupByKey and join; org.apache.spark.rdd.DoubleRDDFunctions contains operations available only on RDDs of Doubles; and org.apache.spark.rdd.SequenceFileRDDFunctions contains operations available on RDDs that can be saved as SequenceFiles. These operations are automatically available on any RDD of the right type (e.g. RDD[(Int, Int)] through implicit conversions.

    Java programmers should reference the org.apache.spark.api.java package for Spark programming APIs in Java.

    Classes and methods marked with Experimental are user-facing features which have not been officially adopted by the Spark project. These are subject to change or removal in minor releases.

    Classes and methods marked with Developer API are intended for advanced users want to extend Spark through lower level interfaces. These are subject to changes or removal in minor releases.

    Definition Classes
    apache
  • package mllib

    RDD-based machine learning APIs (in maintenance mode).

    RDD-based machine learning APIs (in maintenance mode).

    The spark.mllib package is in maintenance mode as of the Spark 2.0.0 release to encourage migration to the DataFrame-based APIs under the org.apache.spark.ml package. While in maintenance mode,

    • no new features in the RDD-based spark.mllib package will be accepted, unless they block implementing new features in the DataFrame-based spark.ml package;
    • bug fixes in the RDD-based APIs will still be accepted.

    The developers will continue adding more features to the DataFrame-based APIs in the 2.x series to reach feature parity with the RDD-based APIs. And once we reach feature parity, this package will be deprecated.

    Definition Classes
    spark
    See also

    SPARK-4591 to track the progress of feature parity

  • package recommendation
    Definition Classes
    mllib
  • ALS
  • MatrixFactorizationModel
  • Rating

class ALS extends Serializable with Logging

Alternating Least Squares matrix factorization.

ALS attempts to estimate the ratings matrix R as the product of two lower-rank matrices, X and Y, i.e. X * Yt = R. Typically these approximations are called 'factor' matrices. The general approach is iterative. During each iteration, one of the factor matrices is held constant, while the other is solved for using least squares. The newly-solved factor matrix is then held constant while solving for the other factor matrix.

This is a blocked implementation of the ALS factorization algorithm that groups the two sets of factors (referred to as "users" and "products") into blocks and reduces communication by only sending one copy of each user vector to each product block on each iteration, and only for the product blocks that need that user's feature vector. This is achieved by precomputing some information about the ratings matrix to determine the "out-links" of each user (which blocks of products it will contribute to) and "in-link" information for each product (which of the feature vectors it receives from each user block it will depend on). This allows us to send only an array of feature vectors between each user block and product block, and have the product block find the users' ratings and update the products based on these messages.

For implicit preference data, the algorithm used is based on "Collaborative Filtering for Implicit Feedback Datasets", available at here, adapted for the blocked approach used here.

Essentially instead of finding the low-rank approximations to the rating matrix R, this finds the approximations for a preference matrix P where the elements of P are 1 if r > 0 and 0 if r <= 0. The ratings then act as 'confidence' values related to strength of indicated user preferences rather than explicit ratings given to items.

Note: the input rating RDD to the ALS implementation should be deterministic. Nondeterministic data can cause failure during fitting ALS model. For example, an order-sensitive operation like sampling after a repartition makes RDD output nondeterministic, like rdd.repartition(2).sample(false, 0.5, 1618). Checkpointing sampled RDD or adding a sort before sampling can help make the RDD deterministic.

Annotations
@Since( "0.8.0" )
Source
ALS.scala
Linear Supertypes
Logging, Serializable, Serializable, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. ALS
  2. Logging
  3. Serializable
  4. Serializable
  5. AnyRef
  6. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new ALS()

    Constructs an ALS instance with default parameters: {numBlocks: -1, rank: 10, iterations: 10, lambda: 0.01, implicitPrefs: false, alpha: 1.0}.

    Constructs an ALS instance with default parameters: {numBlocks: -1, rank: 10, iterations: 10, lambda: 0.01, implicitPrefs: false, alpha: 1.0}.

    Annotations
    @Since( "0.8.0" )

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native() @IntrinsicCandidate()
  6. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  7. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  8. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @IntrinsicCandidate()
  9. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @IntrinsicCandidate()
  10. def initializeLogIfNecessary(isInterpreter: Boolean, silent: Boolean): Boolean
    Attributes
    protected
    Definition Classes
    Logging
  11. def initializeLogIfNecessary(isInterpreter: Boolean): Unit
    Attributes
    protected
    Definition Classes
    Logging
  12. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  13. def isTraceEnabled(): Boolean
    Attributes
    protected
    Definition Classes
    Logging
  14. def log: Logger
    Attributes
    protected
    Definition Classes
    Logging
  15. def logDebug(msg: ⇒ String, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  16. def logDebug(msg: ⇒ String): Unit
    Attributes
    protected
    Definition Classes
    Logging
  17. def logError(msg: ⇒ String, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  18. def logError(msg: ⇒ String): Unit
    Attributes
    protected
    Definition Classes
    Logging
  19. def logInfo(msg: ⇒ String, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  20. def logInfo(msg: ⇒ String): Unit
    Attributes
    protected
    Definition Classes
    Logging
  21. def logName: String
    Attributes
    protected
    Definition Classes
    Logging
  22. def logTrace(msg: ⇒ String, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  23. def logTrace(msg: ⇒ String): Unit
    Attributes
    protected
    Definition Classes
    Logging
  24. def logWarning(msg: ⇒ String, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  25. def logWarning(msg: ⇒ String): Unit
    Attributes
    protected
    Definition Classes
    Logging
  26. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  27. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @IntrinsicCandidate()
  28. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @IntrinsicCandidate()
  29. def run(ratings: JavaRDD[Rating]): MatrixFactorizationModel

    Java-friendly version of ALS.run.

    Java-friendly version of ALS.run.

    Annotations
    @Since( "1.3.0" )
  30. def run(ratings: RDD[Rating]): MatrixFactorizationModel

    Run ALS with the configured parameters on an input RDD of Rating objects.

    Run ALS with the configured parameters on an input RDD of Rating objects. Returns a MatrixFactorizationModel with feature vectors for each user and product.

    Annotations
    @Since( "0.8.0" )
  31. def setAlpha(alpha: Double): ALS.this.type

    Sets the constant used in computing confidence in implicit ALS.

    Sets the constant used in computing confidence in implicit ALS. Default: 1.0.

    Annotations
    @Since( "0.8.1" )
  32. def setBlocks(numBlocks: Int): ALS.this.type

    Set the number of blocks for both user blocks and product blocks to parallelize the computation into; pass -1 for an auto-configured number of blocks.

    Set the number of blocks for both user blocks and product blocks to parallelize the computation into; pass -1 for an auto-configured number of blocks. Default: -1.

    Annotations
    @Since( "0.8.0" )
  33. def setCheckpointInterval(checkpointInterval: Int): ALS.this.type

    Set period (in iterations) between checkpoints (default = 10).

    Set period (in iterations) between checkpoints (default = 10). Checkpointing helps with recovery (when nodes fail) and StackOverflow exceptions caused by long lineage. It also helps with eliminating temporary shuffle files on disk, which can be important when there are many ALS iterations. If the checkpoint directory is not set in org.apache.spark.SparkContext, this setting is ignored.

    Annotations
    @Since( "1.4.0" )
  34. def setFinalRDDStorageLevel(storageLevel: StorageLevel): ALS.this.type

    Sets storage level for final RDDs (user/product used in MatrixFactorizationModel).

    Sets storage level for final RDDs (user/product used in MatrixFactorizationModel). The default value is MEMORY_AND_DISK. Users can change it to a serialized storage, e.g. MEMORY_AND_DISK_SER and set spark.rdd.compress to true to reduce the space requirement, at the cost of speed.

    Annotations
    @Since( "1.3.0" )
  35. def setImplicitPrefs(implicitPrefs: Boolean): ALS.this.type

    Sets whether to use implicit preference.

    Sets whether to use implicit preference. Default: false.

    Annotations
    @Since( "0.8.1" )
  36. def setIntermediateRDDStorageLevel(storageLevel: StorageLevel): ALS.this.type

    Sets storage level for intermediate RDDs (user/product in/out links).

    Sets storage level for intermediate RDDs (user/product in/out links). The default value is MEMORY_AND_DISK. Users can change it to a serialized storage, e.g., MEMORY_AND_DISK_SER and set spark.rdd.compress to true to reduce the space requirement, at the cost of speed.

    Annotations
    @Since( "1.1.0" )
  37. def setIterations(iterations: Int): ALS.this.type

    Set the number of iterations to run.

    Set the number of iterations to run. Default: 10.

    Annotations
    @Since( "0.8.0" )
  38. def setLambda(lambda: Double): ALS.this.type

    Set the regularization parameter, lambda.

    Set the regularization parameter, lambda. Default: 0.01.

    Annotations
    @Since( "0.8.0" )
  39. def setNonnegative(b: Boolean): ALS.this.type

    Set whether the least-squares problems solved at each iteration should have nonnegativity constraints.

    Set whether the least-squares problems solved at each iteration should have nonnegativity constraints.

    Annotations
    @Since( "1.1.0" )
  40. def setProductBlocks(numProductBlocks: Int): ALS.this.type

    Set the number of product blocks to parallelize the computation.

    Set the number of product blocks to parallelize the computation.

    Annotations
    @Since( "1.1.0" )
  41. def setRank(rank: Int): ALS.this.type

    Set the rank of the feature matrices computed (number of features).

    Set the rank of the feature matrices computed (number of features). Default: 10.

    Annotations
    @Since( "0.8.0" )
  42. def setSeed(seed: Long): ALS.this.type

    Sets a random seed to have deterministic results.

    Sets a random seed to have deterministic results.

    Annotations
    @Since( "1.0.0" )
  43. def setUserBlocks(numUserBlocks: Int): ALS.this.type

    Set the number of user blocks to parallelize the computation.

    Set the number of user blocks to parallelize the computation.

    Annotations
    @Since( "1.1.0" )
  44. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  45. def toString(): String
    Definition Classes
    AnyRef → Any
  46. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  47. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native()
  48. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Deprecated Value Members

  1. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] ) @Deprecated
    Deprecated

Inherited from Logging

Inherited from Serializable

Inherited from Serializable

Inherited from AnyRef

Inherited from Any

Ungrouped