File tree Expand file tree Collapse file tree 1 file changed +4
-2
lines changed
examples/src/main/scala/org/apache/spark/examples/mllib Expand file tree Collapse file tree 1 file changed +4
-2
lines changed Original file line number Diff line number Diff line change 1919package org .apache .spark .examples .mllib
2020
2121import org .apache .spark .{SparkConf , SparkContext }
22+ import org .apache .spark .util .Utils
2223
2324object StratifiedSamplingExample {
2425
@@ -34,11 +35,12 @@ object StratifiedSamplingExample {
3435
3536 // specify the exact fraction desired from each key
3637 val fractions = Map (1 -> 0.1 , 2 -> 0.6 , 3 -> 0.3 )
38+ val seed = Utils .random.nextLong
3739
3840 // Get an approximate sample from each stratum
39- val approxSample = data.sampleByKey(withReplacement = false , fractions)
41+ val approxSample = data.sampleByKey(withReplacement = false , fractions = fractions, seed )
4042 // Get an exact sample from each stratum
41- val exactSample = data.sampleByKeyExact(withReplacement = false , fractions)
43+ val exactSample = data.sampleByKeyExact(withReplacement = false , fractions = fractions, seed )
4244 // $example off$
4345
4446 println(" approxSample size is " + approxSample.collect().size.toString)
You can’t perform that action at this time.
0 commit comments