如何将mllib als结果导出到文本文件Spark [英] How to export mllib als results into text file Spark

查看:86
本文介绍了如何将mllib als结果导出到文本文件Spark的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Spark的新手.我正在尝试运行一种协作式过滤算法,并且做到了.现在,我想知道如何将用户建议放入文本文件或mysql数据集中?

I'm new in Spark. I'm trying to run a collaborative filtering algorithm and I made it. Now I want to know how can I put users recommendations into a text file or a mysql data set?

例如在我的Spark Shell中:

For example in my spark shell:

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存储评级对象,即:

You could do this in 2 ways: 1 store the rating objects ie:

topKRecs.saveAsObjectFile("path")

2将值存储为输出文件

2 store the values as output file

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

这篇关于如何将mllib als结果导出到文本文件Spark的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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