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 similar items

Let's see what the title of our chosen movie is:

println(titles(itemId))

The preceding code will print the following output:

    Wes Craven's New Nightmare (1994)

As we did for user recommendations, we can sense check our item-to-item similarity computations and take a look at the titles of the most similar movies. This time, we will take the top 11, so that we can exclude our given movie. So, we will take the numbers 1 to 11 in the list:

val sortedSims2 = sims.top(K + 1)(Ordering.by[(Int, Double),    Double] { case (id, similarity) => similarity }) sortedSims2.slice(1, 11).map{ case (id, sim) => (titles(id), sim)    }.mkString("n")

You will see the movie titles and scores displayed similar to this output:

(Hideaway ...

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