val Array(f1,f2) = data.randomSplit(Array(0.97, 0.03))
它将使用提供的权重拆分数据 .
6
你应该使用 randomSplit 方法:
def randomSplit(weights: Array[Double], seed: Long = Utils.random.nextLong): Array[RDD[T]]
// Randomly splits this RDD with the provided weights.
// weights for splits, will be normalized if they don't sum to 1
// returns split RDDs in an array
def randomSplit(weights: Array[Double], seed: Long = Utils.random.nextLong): Array[RDD[T]] = {
val sum = weights.sum
val normalizedCumWeights = weights.map(_ / sum).scanLeft(0.0d)(_ + _)
normalizedCumWeights.sliding(2).map { x =>
new PartitionwiseSampledRDD[T, T](this, new BernoulliSampler[T](x(0), x(1)),seed)
}.toArray
}
2 回答
我找到了一种简单快捷的方法来分割数组:
它将使用提供的权重拆分数据 .
你应该使用
randomSplit
方法:这是它在火花1.0中的implementation: