- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这个问题解释了Spark的随机分割是如何工作的,How does Sparks RDD.randomSplit actually split the RDD ,但我不明白 Spark 如何跟踪哪些值进入一个拆分,以便这些相同的值不会进入第二个拆分。
如果我们看一下 randomSplit 的实现:
def randomSplit(weights: Array[Double], seed: Long): Array[DataFrame] = {
// It is possible that the underlying dataframe doesn't guarantee the ordering of rows in its
// constituent partitions each time a split is materialized which could result in
// overlapping splits. To prevent this, we explicitly sort each input partition to make the
// ordering deterministic.
val sorted = Sort(logicalPlan.output.map(SortOrder(_, Ascending)), global = false, logicalPlan)
val sum = weights.sum
val normalizedCumWeights = weights.map(_ / sum).scanLeft(0.0d)(_ + _)
normalizedCumWeights.sliding(2).map { x =>
new DataFrame(sqlContext, Sample(x(0), x(1), withReplacement = false, seed, sorted))
}.toArray
}
我们可以看到它创建了两个共享相同 sqlContext 并具有两个不同 Sample(rs) 的 DataFrame。
这两个 DataFrame 如何相互通信,以便第一个 DataFrame 中的值不会包含在第二个 DataFrame 中?
数据是否被提取两次? (假设sqlContext正在从数据库中选择,该选择是否被执行了两次?)。
最佳答案
这与对 RDD 进行采样完全相同。
假设你有权重数组(0.6, 0.2, 0.2)
,Spark将为每个范围(0.0, 0.6), (0.6, 0.8), (0.8, 1.0)
。
当需要读取结果 DataFrame 时,Spark 将仅遍历父 DataFrame。对于每个项目,生成一个随机数,如果该数字落在指定范围内,则发出该项目。所有子DataFrame共享相同的随机数生成器(从技术上讲,不同的生成器具有相同的种子),因此随机数的序列是确定性的。
对于你的最后一个问题,如果你没有缓存父DataFrame,那么每次计算输出DataFrame时都会重新获取输入DataFrame的数据。
关于apache-spark - Spark 如何跟踪 randomSplit 中的分割?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62159261/
我在 PySpark 中有一个相当大的数据框 (100GB),我想将其拆分为训练集、测试集和验证集。这是关键,我在它工作之前已经完成了,但是这次尝试它时,它返回的数据帧的所有值都从实际值更改为 1 或
我正在尝试使用以下方法将数据集拆分为训练和非训练 inDataSet.randomSplit(weights.toArray, 0) 每次运行,我都会得到不同的结果。这是预期的吗?如果是这样,我怎样才
假设我有类似下面的代码 for idx in xrange(0, 10): train_test_split = training.randomSplit(weights=[0.75, 0.2
这个问题解释了 Spark 的随机拆分是如何工作的,How does Sparks RDD.randomSplit actually split the RDD ,但我不明白 spark 如何跟踪第一
这个问题解释了Spark的随机分割是如何工作的,How does Sparks RDD.randomSplit actually split the RDD ,但我不明白 Spark 如何跟踪哪些值进
嗨,我是 MLlib 的新手,我正在阅读 Spark 网站上有关它的文档。我很难理解为什么在下面的代码中我们需要缓存“0”用于训练和“1”用于测试: val splits = data.rando
所以假设我有一个包含 3000 行的 rdd。前 2000 行属于 1 类,最后 1000 行属于 2 类。RDD 分为 100 个分区。 调用RDD.randomSplit(0.8,0.2)时 该函
我用我的数据创建了一个 DataFrame 来运行一些机器学习实验。我试图通过使用 randomSplit() 函数将它分成训练集和测试集,但它给了我一些我无法弄清楚原因的异常。我的代码与此类似: F
我是一名优秀的程序员,十分优秀!