Step 5 - Prepare the data for building the recommendation model using ALS

The ALS algorithm takes the RDD of ratings for training. To do so, the following code illustrates for building the recommendation model using APIs:

val ratingsRDD = trainingData.rdd.map(row => {                     val userId = row.getString(0)                     val movieId = row.getString(1)                     val ratings = row.getString(2)                     Rating(userId.toInt, movieId.toInt, ratings.toDouble)})

The ratingsRDD is an RDD of ratings that contains userId, movieId, and the corresponding ratings from the training dataset we prepared in the previous step. On the other hand, a test RDD is also required for evaluating the model. The following testRDD also contains the same information coming from the test DataFrame we prepared ...

Get Scala Machine Learning Projects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.