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

    https://github.com/apache/spark/pull/3098#discussion_r20002546
  
    --- 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 --
    
    I was going to comment on this point too - MAP has a max of 1.0.
    
    The input to `RankingMetrics` should be RDD[(predicted IDs array), (ground 
truth IDs array)], where the predictions are ordered by score (position matters 
for avg precision at K).


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