pyspark毫升推荐 - 所有recomendation [英] pyspark ml recommendation - All recomendation

查看:610
本文介绍了pyspark毫升推荐 - 所有recomendation的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

海兰,

我在星火新我使用ML推荐尝试。

I'm new in Spark and I'm trying using ML recommendation.

我的code

df = sqlContext.createDataFrame(
[(0, 0, 4.0), (0, 1, 2.0), (1, 1, 3.0), (1, 2, 4.0), (2, 1, 1.0), (2, 2, 5.0)],
["user", "item", "rating"])

als = ALS(rank=10, maxIter=5)

model = als.fit(df)

model.userFactors.orderBy("id").collect()

我如何获得所有用户的所有电影2建议?

How can I obtain 2 recommendation for all users for all movies?

感谢您的时间。

推荐答案

这是不能直接用 ml.recommendation.ALSModel 。你可以使用变换

It is not directly possible with ml.recommendation.ALSModel. You could use transform method

users = df.select("user").distinct()
items = df.select("item").distinct()

model.transform(users.join(items))

和筛选后的结果,但它是非常低效的。至于我可以告诉倒不如简单地使用 mllib.recommendation.ALS 这里:

and filter the results afterwards but it is extremely inefficient. As far as I can tell it would be better to simply use mllib.recommendation.ALS here:

from pyspark.mllib.recommendation import ALS, Rating

model = ALS.train(df.rdd.map(lambda r: Rating(*r)), 10, 5)
model.recommendProductsForUsers(2)

这篇关于pyspark毫升推荐 - 所有recomendation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆