Github user MLnick commented on a diff in the pull request:
https://github.com/apache/spark/pull/14321#discussion_r72415601
--- 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))
--- End diff --
does it make sense perhaps to have a convenience version of
`randomSplitByKey` that takes an `Array[Double]` for weights and applies the
same sampling weight for each key? Since I would expect the vast majority of
the time the use case is to split the dataset into folds with the same sampling
ratio across keys?
---
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]