我有一个 RDD[(String,Array[String])],我需要复制其中的数据以增加其大小。
我读过这里https://stackoverflow.com/a/41787801/9759150通过 replacemente,您可以在样本中获得相同的元素两次。
例如:
如果 RDD.count() 是 35 个元素,我需要从中生成一个包含 200 个元素的 RDD。我怎样才能做到这一点?
我看到应用示例是这样的:
val sampledRDD = rdd.sample(true, fraction, seed)
我不知道如何为我的问题选择fraction
参数。
谢谢!
最佳答案
我做了一些测试,我发现 .sample() 能够做我想要的事情!关键是保持 true
中的替换(正如我在问题中所说),seed
可以是任何东西(当然是数字),但是 fraction
应该是:
val fraction = num_new.toDouble / rdd.count() // following my examle: num_new is 200, and rdd.count() is 35
val sampledRDD = rdd.sample(true, fraction, seed)
在本例中,fraction = 5.71428571428571
,这意味着 sampledRDD
的每个元素都会重复 fraction
次。
关于scala - Spark : increase the size of an RDD using sample with replacement,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50381477/