Apache spark ALS建议的笛卡尔积误差
我正在尝试向用户显示电影推荐列表。该模型已经过训练,但当试图显示预测时,我得到了一个错误Apache spark ALS建议的笛卡尔积误差,apache-spark,pyspark,Apache Spark,Pyspark,我正在尝试向用户显示电影推荐列表。该模型已经过训练,但当试图显示预测时,我得到了一个错误 als = ALS(maxIter=5, regParam=0.01, userCol="userID", itemCol="movieID", ratingCol="rating") # ratings is a DataFrame of (movieID, rating, userID) model = als.fit(ratings) # allMovies is a DataFrame of (m
als = ALS(maxIter=5, regParam=0.01, userCol="userID",
itemCol="movieID", ratingCol="rating")
# ratings is a DataFrame of (movieID, rating, userID)
model = als.fit(ratings)
# allMovies is a DataFrame of (movieID, userID)
# it has userID=0 and all distinct movieID
recommendations = model.transform(allMovies)
recommendations.take(20)
使用pyspark.ml.recommendation.ALS中的库和
当运行最后一行时,我得到了错误
检测到逻辑计划之间左外联接的笛卡尔积
为什么会这样?谢谢 在model.transform之前,您必须定义类似ALS的ALS(输入\列='类似输入功能',输出\列=预测\评级),或者您可以采用这种方式工作
rank = 10
numIterations = 100
model = ALS.train(ratings, rank, numIterations) #where ratings is dataframe
recommendation = model.predictAll(alMovies).map(lambda r: ((r[0], r[1]), r[2]))
希望这有帮助。回答我自己的问题。您似乎不应该使用transform
,而是使用recommendForUserSubset
方法。很抱歉,我无法使用此代码。无论如何,谢谢你的帮助!似乎您已经找到了解决方案,只是出于好奇,在使用上述代码时出现了什么错误?当然,我得到了一个AttributeError:“ALS”对象没有属性“train”