Github user mengxr commented on a diff in the pull request:

    https://github.com/apache/spark/pull/3098#discussion_r20050413
  
    --- Diff: 
examples/src/main/scala/org/apache/spark/examples/mllib/MovieLensALS.scala ---
    @@ -135,8 +141,11 @@ object MovieLensALS {
     
         println(s"Got $numRatings ratings from $numUsers users on $numMovies 
movies.")
     
    -    val splits = ratings.randomSplit(Array(0.8, 0.2))
    -    val training = splits(0).cache()
    +    val fractions = (0 until numUsers.toInt).map(x => (x + 1, 0.8)).toMap
    +    
    +    val training = ratings.map { x => (x.user, x) }.sampleByKey(false, 
fractions).map { x => x._2 }
    --- End diff --
    
    `sampleByKey` with the same `fraction` for each group is the same as 
`sample(false, fraction)`. If you use `sampleByKeyExact`, we need to collect 
the keys to driver, which is expensive. I think we can keep the simple 
`randomSplit` code, and in evaluation, we use a outer join and define a metric 
for those not appeared in training.


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to