O'Reilly logo

R Data Analysis Cookbook - Second Edition by Kuntal Ganguly

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

Movie lens recommendation system with SparkR

In the earlier recipe with R and MySQL, we set up a recommendation database with a rating table containing movie-lens data. We will fetch the data from MySQL using the SparkR read.jdbc() function, then use the Alternating Least Square (ALS) recommendation algorithm on the data examples to generate a predictive model:

> jdbcUrl="jdbc:mysql://localhost:3306/recommendation"> dfRates = read.jdbc(jdbcUrl, "recommendation.rating", user = "root", password = "root")> df_list <- randomSplit(dfRates, c(7,3), 2)> recommendDF <- df_list[[1]]> recommendTestDF <- df_list[[2]]># Fit a recommendation model using ALS with spark.als> model <- spark.als(recommendDF, maxIter = 5, regParam = 0.01, userCol = "userId",itemCol ...

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