- Table of contents {:toc}

## Collaborative filtering

Collaborative filtering is commonly used for recommender systems. These techniques aim to fill in the missing entries of a user-item association matrix. `spark.mllib`

currently supports model-based collaborative filtering, in which users and products are described by a small set of latent factors that can be used to predict missing entries. `spark.mllib`

uses the alternating least squares (ALS) algorithm to learn these latent factors. The implementation in `spark.mllib`

has the following parameters:

*numBlocks*is the number of blocks used to parallelize computation (set to -1 to auto-configure).*rank*is the number of features to use (also referred to as the number of latent factors).*iterations*is the number of iterations of ALS to run. ALS typically converges to a reasonable solution in 20 iterations or less.*lambda*specifies the regularization parameter in ALS.*implicitPrefs*specifies whether to use the*explicit feedback*ALS variant or one adapted for*implicit feedback*data.*alpha*is a parameter applicable to the implicit feedback variant of ALS that governs the*baseline*confidence in preference observations.

### Explicit vs. implicit feedback

The standard approach to matrix factorization-based collaborative filtering treats the entries in the user-item matrix as *explicit* preferences given by the user to the item, for example, users giving ratings to movies.

It is common in many real-world use cases to only have access to *implicit feedback* (e.g. views, clicks, purchases, likes, shares etc.). The approach used in `spark.mllib`

to deal with such data is taken from Collaborative Filtering for Implicit Feedback Datasets. Essentially, instead of trying to model the matrix of ratings directly, this approach treats the data as numbers representing the *strength* in observations of user actions (such as the number of clicks, or the cumulative duration someone spent viewing a movie). Those numbers are then related to the level of confidence in observed user preferences, rather than explicit ratings given to items. The model then tries to find latent factors that can be used to predict the expected preference of a user for an item.

### Scaling of the regularization parameter

Since v1.1, we scale the regularization parameter `lambda`

in solving each least squares problem by the number of ratings the user generated in updating user factors, or the number of ratings the product received in updating product factors. This approach is named "ALS-WR" and discussed in the paper "Large-Scale Parallel Collaborative Filtering for the Netflix Prize". It makes `lambda`

less dependent on the scale of the dataset, so we can apply the best parameter learned from a sampled subset to the full dataset and expect similar performance.

## Examples

In order to run the above application, follow the instructions provided in the Self-Contained Applications section of the Spark Quick Start guide. Be sure to also include *spark-mllib* to your build file as a dependency.

## Tutorial

The training exercises from the Spark Summit 2014 include a hands-on tutorial for personalized movie recommendation with `spark.mllib`

.