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

Inspecting the recommendations

We can give these recommendations a sense check by taking a quick look at the titles of the movies a user has rated and the recommended movies. First, we will need to load the movie data, which is one of the datasets we explored in the previous chapter. In the following code we'll collect this data as a Map[Int, String] method, mapping the movie ID to the title:

val movies = sc.textFile("/PATH/ml-100k/u.item") val titles = movies.map(line =>    line.split("|").take(2)).map(array => (array(0).toInt,   array(1))).collectAsMap() titles(123)

The preceding code will produce the following output:

res68: String = Frighteners, The (1996)

For our user 789, we can find out what movies they have rated, take the 10 movies ...

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