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}.
Java-friendly version of ALS.run.
Java-friendly version of ALS.run.
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.
Sets the constant used in computing confidence in implicit ALS.
Sets the constant used in computing confidence in implicit ALS. Default: 1.0.
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.
:: DeveloperApi :: Set period (in iterations) between checkpoints (default = 10).
:: DeveloperApi :: 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.
:: DeveloperApi :: Sets storage level for final RDDs (user/product used in MatrixFactorizationModel).
:: DeveloperApi ::
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.
Sets whether to use implicit preference.
Sets whether to use implicit preference. Default: false.
:: DeveloperApi :: Sets storage level for intermediate RDDs (user/product in/out links).
:: DeveloperApi ::
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.
Set the number of iterations to run.
Set the number of iterations to run. Default: 10.
Set the regularization parameter, lambda.
Set the regularization parameter, lambda. Default: 0.01.
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.
Set the number of product blocks to parallelize the computation.
Set the number of product blocks to parallelize the computation.
Set the rank of the feature matrices computed (number of features).
Set the rank of the feature matrices computed (number of features). Default: 10.
Sets a random seed to have deterministic results.
Sets a random seed to have deterministic results.
Set the number of user blocks to parallelize the computation.
Set the number of user blocks to parallelize the computation.
Alternating Least Squares matrix factorization.
ALS attempts to estimate the ratings matrix
R
as the product of two lower-rank matrices,X
andY
, 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 http://dx.doi.org/10.1109/ICDM.2008.22, 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 matrixP
where the elements ofP
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.