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

FP-Growth Applied to Movie Lens Data

Let's apply the algorithm to Movie Lens data to find our frequent movie titles:

  1. Instantiate the SparkContext by writing the following lines of code:
        val sc = Util.sc         val rawData = Util.getUserData()         rawData.first()
  1. Get raw ratings and print first by writing the following lines of code:
        val rawRatings = rawData.map(_.split("t").take(3))         rawRatings.first()         val ratings = rawRatings.map { case Array(user, movie,            rating) =>         Rating(user.toInt, movie.toInt, rating.toDouble) }             val ratingsFirst = ratings.first()         println(ratingsFirst)
  1. Load the movie data and get the titles as follows:
        val movies = Util.getMovieData()         val titles = movies.map(line =>         line.split("|").take(2)).map(array  => (array(0).toInt, ...

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