0
我正在使用PySpark,我正在尋找一種方法將RDD隨機分爲n個公平的部分。下式給出:randomSplit不尊重特定權重PySpark
RDD = sc.parallelize(range(50))
我的代碼:
from itertools import repeat
def split_population_into_parts(rdd):
N = 4
weight_part = float(1)/float(N)
weights_list = list(repeat(weight_part, N))
repartionned_rdd = rdd.randomSplit(weights = weights_list)
#And just to check what weights give, I did :
for i in repartionned_rdd:
print len(i.collect())
split_population_into_parts(rdd = RDD)
明知權重= [0.25,0.25,0.25,0.25],我的代碼可以給爲例(如RDD長度):
9
19
11
11
爲什麼randomSplit不尊重這裏的權重?我想要例如12,12,12和14作爲長度,或者12,12,13和13。什麼是最有效的方法來做到這一點?謝謝 !
LostInOverflow:謝謝,但沒有真正的方法來衡量零部件? – DataAddicted
具有良好的統計特性和良好的性能?可能不會。如果你真的需要這個,你可以通過隨機鍵,zipWithIndex進行排序,並執行多個顯式範圍的過濾器。 – 2016-11-15 10:25:37