Github user MLnick commented on a diff in the pull request:
https://github.com/apache/spark/pull/14321#discussion_r74469122
--- Diff:
mllib/src/main/scala/org/apache/spark/ml/tuning/TrainValidationSplit.scala ---
@@ -98,7 +105,21 @@ class TrainValidationSplit @Since("1.5.0")
(@Since("1.5.0") override val uid: St
val metrics = new Array[Double](epm.length)
val Array(trainingDataset, validationDataset) =
- dataset.randomSplit(Array($(trainRatio), 1 - $(trainRatio)), $(seed))
+ if ($(stratifiedCol).nonEmpty) {
+ val stratifiedColIndex =
schema.fieldNames.indexOf($(stratifiedCol))
+ val pairData = dataset.toDF.rdd.map(row =>
(row(stratifiedColIndex), row))
+ val keys = pairData.keys.distinct.collect()
+ val weights: Array[scala.collection.Map[Any, Double]] =
+ Array(keys.map((_, $(trainRatio))).toMap, keys.map((_, 1 -
$(trainRatio))).toMap)
+ val splitsWithKeys = pairData.randomSplitByKey(weights, exact =
true, $(seed))
+ val Array(training, validation) =
--- End diff --
This illustrates a bit of a difference in API from `RDD.randomSplit`. I
think it may be a little confusing for users who might expect the same
semantics. I think we might need to either provide a `withComplement` flag and
have a version of `randomSplitByKey` that returns just the `Array[RDD]` to
match `randomSplit` semantics.
What do you think of that?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]