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

    https://github.com/apache/spark/pull/3098#discussion_r19980455
  
    --- Diff: 
examples/src/main/scala/org/apache/spark/examples/mllib/MovieLensALS.scala ---
    @@ -165,22 +169,60 @@ object MovieLensALS {
           .setProductBlocks(params.numProductBlocks)
           .run(training)
     
    -    val rmse = computeRmse(model, test, params.implicitPrefs)
    -
    -    println(s"Test RMSE = $rmse.")
    -
    +    val (rmse, userMap, productMap) = 
    +      computeRecommendationMetrics(model, test, params.implicitPrefs)
    +    
    +    println(s"Test RMSE = $rmse user MAP = $userMap product MAP = 
$productMap.")
    +    
         sc.stop()
       }
    -
    -  /** Compute RMSE (Root Mean Squared Error). */
    -  def computeRmse(model: MatrixFactorizationModel, data: RDD[Rating], 
implicitPrefs: Boolean) = {
    -
    -    def mapPredictedRating(r: Double) = if (implicitPrefs) 
math.max(math.min(r, 1.0), 0.0) else r
    -
    +  
    +  /**  
    +   * Threshold for predictions are at 0.5
    +   */
    +  def mapPredictedRating(r: Double, implicitPrefs: Boolean) = {
    +    if (implicitPrefs) math.max(math.min(r, 1.0), 0.0)
    +    else math.max(round(r), 0.0)
    +  }
    +  
    +  /**  
    +   * Compute MAP (Mean Average Precision) statistics
    +   */
    +  def computeMap(predictedAndLabels: RDD[(Int, (Double, Double))]) = {
    +     val ranking = predictedAndLabels.groupByKey.map {
    +      case (user, entries) => {
    +        val predictionValues = entries.toArray
    --- End diff --
    
    Please kindly point out if I understand incorrectly. Is the `entries` here 
be the value of ratings? The `predictedAndLables` is supposed to (predicted ID, 
true ID), but not (predicted rating, true rating). I think this might also be 
the reason you get an MAP value great than 1.0, which is by definition not 
possible...


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