星火 - 斯卡拉:洗牌RDD /分RDD成两个随机配件随机 [英] Spark - scala: shuffle RDD / split RDD into two random parts randomly

查看:311
本文介绍了星火 - 斯卡拉:洗牌RDD /分RDD成两个随机配件随机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何采取火花的RDD阵列,它分成两个RDDS随机所以每个RDD将包括数据的某些部分(可以说97%和3%)。

How can I take a rdd array of spark, and split it into two rdds randomly so each rdd will include some part of data (lets say 97% and 3%).

我想洗牌的列表,然后 shuffledList.take((0.97 * rddList.count).toInt)

I thought to shuffle the list and then shuffledList.take((0.97*rddList.count).toInt)

但我怎么能洗好RDD?

But how can I Shuffle the rdd?

还是有更好的方式来分割列表?

Or is there a better way to split the list?

推荐答案

我发现了一个简单,快捷的方式分割数组:

I've found a simple and fast way to split the array:

val Array(f1,f2) = data.randomSplit(Array(0.97, 0.03))

这将使用所提供的权重分割数据。

It will split the data using the provided weights.

这篇关于星火 - 斯卡拉:洗牌RDD /分RDD成两个随机配件随机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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