You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2022/10/11 08:28:29 UTC

[GitHub] [spark] zhengruifeng commented on pull request #38203: [SPARK-40745][MLLIB] Reduce the shuffle size of ALS in `.mllib`

zhengruifeng commented on PR #38203:
URL: https://github.com/apache/spark/pull/38203#issuecomment-1274301748

   take [`RankingMetricsExample`](https://github.com/apache/spark/blob/e3058ba17cb4512537953eb4ded884e24ee93ba2/examples/src/main/scala/org/apache/spark/examples/mllib/RankingMetricsExample.scala) for example:
   
   ```
   import org.apache.spark.mllib.evaluation.{RankingMetrics, RegressionMetrics}
   import org.apache.spark.mllib.recommendation.{ALS, Rating}
   
   
   val ratings = spark.read.textFile("data/mllib/sample_movielens_data.txt").rdd.map { line =>
       val fields = line.split("::")
       Rating(fields(0).toInt, fields(1).toInt, fields(2).toDouble - 2.5)
   }.cache()
   
   // Map ratings to 1 or 0, 1 indicating a movie that should be recommended
   val binarizedRatings = ratings.map(r => Rating(r.user, r.product, if (r.rating > 0) 1.0 else 0.0)).cache()
   
   
   val numIterations = 1
   val rank = 10
   val lambda = 0.01
   val model = ALS.train(ratings, rank, numIterations, lambda)
   
   val userRecommended = model.recommendProductsForUsers(10)
   
   userRecommended.count()
   ```
   
   before:
   ![image](https://user-images.githubusercontent.com/7322292/195038806-acad9193-838e-4a32-9ec4-5e390d143e61.png)
   
   
   after:
   ![image](https://user-images.githubusercontent.com/7322292/195038629-9b249726-05a2-4b90-a804-7aef089f505f.png)
   
   the shuffle size was reduced from `310.1 KiB` to `110.9 KiB`


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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