Permalink
Browse files

Code review follow up.

  • Loading branch information...
1 parent 7cb34ca commit 97b6b5d85679497f5b5305920d638a443543379f @holdenk committed Feb 24, 2014
@@ -63,6 +63,8 @@ class BernoulliSampler[T](lb: Double, ub: Double, complement: Boolean = false)
}
}
+ def cloneComplement() = new BernoulliSampler[T](lb, ub, !complement)
+
override def clone = new BernoulliSampler[T](lb, ub, complement)
}
@@ -72,12 +72,12 @@ object MLUtils {
*/
def kFold[T : ClassTag](rdd: RDD[T], folds: Int, seed: Int): List[Pair[RDD[T], RDD[T]]] = {
val foldsF = folds.toFloat
- 1.to(folds).map(fold => ((
- new PartitionwiseSampledRDD(rdd, new BernoulliSampler[T]((fold-1)/foldsF,fold/foldsF,
- complement = false), seed),
- new PartitionwiseSampledRDD(rdd, new BernoulliSampler[T]((fold-1)/foldsF,fold/foldsF,
- complement = true), seed)
- ))).toList
+ 1.to(folds).map { fold =>
+ val sampler = new BernoulliSampler[T]((fold-1)/foldsF,fold/foldsF, complement = false)
+ val train = new PartitionwiseSampledRDD(rdd, sampler, seed)
+ val test = new PartitionwiseSampledRDD(rdd, sampler.cloneComplement(), seed)
+ (train, test)
+ }.toList
}
/**

0 comments on commit 97b6b5d

Please sign in to comment.