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

    https://github.com/apache/spark/pull/3098#discussion_r27712646
  
    --- Diff: 
mllib/src/main/scala/org/apache/spark/mllib/recommendation/MatrixFactorizationModel.scala
 ---
    @@ -138,14 +141,122 @@ class MatrixFactorizationModel(
       }
     
       private def recommend(
    -      recommendToFeatures: Array[Double],
    -      recommendableFeatures: RDD[(Int, Array[Double])],
    -      num: Int): Array[(Int, Double)] = {
    -    val scored = recommendableFeatures.map { case (id,features) =>
    -      (id, blas.ddot(features.length, recommendToFeatures, 1, features, 1))
    +    recommendToFeatures: Array[Double],
    +    recommendableFeatures: RDD[(Int, Array[Double])],
    +    num: Int): Array[(Int, Double)] = {
    +    val recommendToVector = Vectors.dense(recommendToFeatures)
    +    val scored = recommendableFeatures.map {
    +      case (id, features) =>
    +        (id, BLAS.dot(recommendToVector, Vectors.dense(features)))
         }
         scored.top(num)(Ordering.by(_._2))
       }
    +
    +  /**
    +   * Recommends topK products for all users
    +   *
    +   * @param num how many products to return for every user.
    +   * @return [(Int, Array[Rating])] objects, where every tuple contains a 
userID and an array of
    +   * rating objects which contains the same userId, recommended productID 
and a "score" in the
    +   * rating field. Semantics of score is same as recommendProducts API
    +   */
    +  def recommendProductsForUsers(num: Int): RDD[(Int, Array[Rating])] = {
    +    val topK = userFeatures.map { x => (x._1, num) }
    --- End diff --
    
    For cross validation we use variable num internally but for final 
recommendation global num is fine...I thought having a topK rdd satisfies both 
use-cases...


---
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