You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by debasish83 <gi...@git.apache.org> on 2015/04/01 00:05:14 UTC

[GitHub] spark pull request: [MLLIB] SPARK-4231, SPARK-3066: Add RankingMet...

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

    https://github.com/apache/spark/pull/3098#discussion_r27528071
  
    --- Diff: examples/src/main/scala/org/apache/spark/examples/mllib/MovieLensALS.scala ---
    @@ -171,18 +175,62 @@ object MovieLensALS {
     
         println(s"Test RMSE = $rmse.")
     
    +    if (params.validateRecommendation) {
    +      val (map, users) = computeRankingMetrics(model,
    +        training, test, numMovies.toInt)
    +      println(s"Test users $users MAP $map")
    +    }
    +    
         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
    -
         val predictions: RDD[Rating] = model.predict(data.map(x => (x.user, x.product)))
    -    val predictionsAndRatings = predictions.map{ x =>
    -      ((x.user, x.product), mapPredictedRating(x.rating))
    +    val predictionsAndRatings = predictions.map { x =>
    +      ((x.user, x.product), mapPredictedRating(x.rating, implicitPrefs))
         }.join(data.map(x => ((x.user, x.product), x.rating))).values
         math.sqrt(predictionsAndRatings.map(x => (x._1 - x._2) * (x._1 - x._2)).mean())
       }
    +
    +  def mapPredictedRating(r: Double, implicitPrefs: Boolean) = {
    +    if (implicitPrefs) math.max(math.min(r, 1.0), 0.0)
    +    else r
    +  }
    +
    +  /**
    +   * Compute MAP (Mean Average Precision) statistics for top N product Recommendation
    +   */
    +  def computeRankingMetrics(model: MatrixFactorizationModel,
    --- End diff --
    
    followed the indentation from current code


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

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