如何将mllib als结果导出到文本文件Spark中

时间:2014-10-26 02:34:52

标签: apache-spark

我是Spark的新手。我正在尝试运行协同过滤算法,我做到了。现在我想知道如何将用户推荐放入文本文件或mysql数据集中?

例如在我的火花壳中:

scala> topKRecs.mkString("\n")
res3: String = 
Rating(101168482,976126,17.762857135595247)
Rating(101168482,298077,15.618423165870723)
Rating(101168482,269474,15.20514216060495)
Rating(101168482,992979001,14.874869183497482)
Rating(101168482,302470001,14.794531500898763)
Rating(101168482,303592,14.779064871786169)
Rating(101168482,1538670001,13.96013790139799)
Rating(101168482,458919,13.905207127505795)
Rating(101168482,1141423,13.882807601308972)
Rating(101168482,992981003,13.844550596026654)

1 个答案:

答案 0 :(得分:0)

你可以通过两种方式做到这一点:   1存储评级对象,即:

topKRecs.saveAsObjectFile("path")

2将值存储为输出文件

topKRecs.map(rating => (rating.user, rating.product, rating.rating)).saveAsTextFile("path")