O'Reilly logo

Machine Learning with Spark - Second Edition by Nick Pentreath, Manpreet Singh Ghotra, Rajdeep Dua

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Generating movie recommendations from the MovieLens 100k dataset

As MLlib's recommendation model is based on matrix factorization, we can use the factor matrices computed by our model to compute predicted scores (or ratings) for a user. We will focus on the explicit rating case using MovieLens data; however, the approach is the same when using the implicit model.

The MatrixFactorizationModel class has a convenient predict method that will compute a predicted score for a given user and item combination as shown in the following code:

val predictedRating = model.predict(789, 123)

The output is as follows:

14/03/30 16:10:10 INFO SparkContext: Starting job: lookup at    MatrixFactorizationModel.scala:4514/03/30 16:10:10 INFO DAGScheduler: Got ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required