使用Spark ALS fit方法时出错

时间:2018-06-14 14:35:55

标签: scala apache-spark apache-spark-ml

我正在使用Spark ALS构建推荐系统。 我的数据如下: +----------------+----------------+------+ | user| item|rating| +----------------+----------------+------+ |1700003729602016|8549869010287270| 10.0| |1700040807808016|1089320000290039| 10.0| |1700203190428016|1759293000286079| 10.0| |1700005989982012|1339117000289746| 10.0|

我尝试使用Mllib构建模型。但是,由于ALS需要评级等级以适应模型,因此我无法做到这一点。我使用的数据有一个格式(Long,Long,Long)和Ratings只允许(Int,Int,Int),并且由于我拥有的用户数量,我无法将Long转换为Int。

所以我尝试使用ML作为此Link suggest来构建模型。但是,我仍然遇到问题。使用我的数据作为RDD,我可以获得userFactors和itemFactors

val (userFactors, itemFactors) = ALS.train(data.rdd )

  

userFactors:org.apache.spark.rdd.RDD [(Long,Array [Float])] = userFactors MapPartitionsRDD [7734] at at mapPartitions at ALS.scala:1010   itemFactors:org.apache.spark.rdd.RDD [(Long,Array [Float])] = itemFactors MapPartitionsRDD [7739] at mapPartitions at ALS.scala:1022   `

但是,如果我尝试使用DataFrame并使用fit方法

val als = new ALS().fit(data.toDF)

我遇到了这个问题:

  

org.apache.spark.SparkException:由于阶段失败导致作业中止:阶段5385.0中的任务0失败1次,最近失败:阶段5385.0中丢失任务0.0(TID 102211,localhost,执行器驱动程序):org.apache .spark.SparkException:无法执行用户定义的函数($ anonfun $ 4:(bigint)=> int)

我认为这个post有类似的问题。但是,我不知道如何处理它,我不知道如何在没有通过createDataset的情况下创建数据集。

0 个答案:

没有答案