我已按照链接http://ampcamp.berkeley.edu/big-data-mini-course/movie-recommendation-with-mllib.html中的指南进行操作
但这已经过时,因为它使用了spark Mlib RDD方法.New Spark 2.0具有DataFrame方法.现在我的问题是我有更新的代码
val ratings = spark.read.textFile("data/mllib/als/sample_movielens_ratings.txt")
.map(parseRating)
.toDF()
val Array(training, test) = ratings.randomSplit(Array(0.8, 0.2))
// Build the recommendation model using ALS on the training data
val als = new ALS()
.setMaxIter(5)
.setRegParam(0.01)
.setUserCol("userId")
.setItemCol("movieId")
.setRatingCol("rating")
val model = als.fit(training)
// Evaluate the model by computing the RMSE on the test data
val predictions = model.transform(test)
Run Code Online (Sandbox Code Playgroud)
现在问题是,在旧代码中,获得的模型是MatrixFactorizationModel,现在它有自己的模型(ALSModel)
在MatrixFactorizationModel中你可以直接做
val recommendations = bestModel.get
.predict(userID)
Run Code Online (Sandbox Code Playgroud)
这将给出用户喜欢它们的概率最高的产品列表.
但现在没有.predict方法.任何想法如何推荐给定用户ID的产品列表