Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Code review follow up.
  • Loading branch information
holdenk committed Apr 9, 2014
commit 5a33f1d6d91e1ec1afb62c920abc0443f13725cf
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class BernoulliSampler[T](lb: Double, ub: Double, complement: Boolean = false)
}
}

def cloneComplement() = new BernoulliSampler[T](lb, ub, !complement)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mark it private[spark] or provide doc? Also, please add return type (my bad).


override def clone = new BernoulliSampler[T](lb, ub, complement)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add return type.

}

Expand Down
12 changes: 6 additions & 6 deletions mllib/src/main/scala/org/apache/spark/mllib/util/MLUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,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
}

/**
Expand Down