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

Extracting features from the MovieLens 100k dataset

In this example, we will use the same MovieLens dataset that we used in the previous chapter. Use the directory in which you placed the MovieLens 100k dataset as the input path in the following code.

First, let's inspect the raw ratings dataset:

object FeatureExtraction { def getFeatures(): Dataset[FeatureExtraction.Rating] = {   val spark = SparkSession.builder.master("local[2]").appName("FeatureExtraction").getOrCreate()   import spark.implicits._   val ratings = spark.read.textFile("/data/ml-100k 2/u.data").map(parseRating)   println(ratings.first())   return ratings } case class Rating(userId: Int, movieId: Int, rating: Float) def parseRating(str: String): Rating = {  val fields = str.split("t") ...

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