【问题标题】:Cartesian product error on ALS recommendationALS 推荐的笛卡尔积错误
【发布时间】:2018-12-11 17:15:18
【问题描述】:

我正在尝试为用户显示电影推荐列表。该模型已经过训练,但在尝试显示预测时出现错误。

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)

使用from pyspark.ml.recommendation.ALS 库和 运行最后一行时,出现错误 Detected cartesian product for LEFT OUTER join between logical plans.

为什么会这样?谢谢!

【问题讨论】:

    标签: apache-spark pyspark


    【解决方案1】:

    为了回答我自己的问题。看来您不应该使用transform,而应该使用recommendForUserSubset 方法。

    【讨论】:

      【解决方案2】:

      在 model.transform 之前,您必须定义 ALS 类似 ALS(input_col = 'something like input feature',output_col = predict_rating) 或者您可以采用这种方式工作。

       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]))
      

      希望这会有所帮助。

      【讨论】:

      • 抱歉,我无法让它与此代码一起使用。无论如何感谢您的帮助!
      • 似乎您已经找到了解决方案,只是为了好奇您在使用上述代码时遇到了什么错误?
      • 当然,我收到了AttributeError: 'ALS' object has no attribute 'train'
      猜你喜欢
      • 2018-04-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-06
      • 2013-12-25
      • 2013-07-14
      相关资源
      最近更新 更多