spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mengxr <...@git.apache.org>
Subject [GitHub] spark pull request: [SPARK-1281] Improve partitioning in ALS
Date Wed, 16 Apr 2014 17:03:12 GMT
Github user mengxr commented on a diff in the pull request:

    https://github.com/apache/spark/pull/407#discussion_r11694652
  
    --- Diff: mllib/src/test/scala/org/apache/spark/mllib/recommendation/ALSSuite.scala ---
    @@ -128,6 +128,47 @@ class ALSSuite extends FunSuite with LocalSparkContext {
         assert(u11 != u2)
       }
     
    +  test("custom partitioner") {
    +    testALS(50, 50, 2, 15, 0.7, 0.3, false, false, false, 3, null)
    +    testALS(50, 50, 2, 15, 0.7, 0.3, false, false, false, 3, new Partitioner {
    +      def numPartitions(): Int = 3
    +      def getPartition(x: Any): Int = x match {
    +        case null => 0
    +        case _ => x.hashCode % 2
    +      }
    +    })
    +  }
    +
    +  test("negative ids") {
    +    val data = ALSSuite.generateRatings(50, 50, 2, 0.7, false, false)
    +    val ratings = data._1.toArray
    +    val correct = data._2
    +    for (i <- 0 until ratings.length) {
    +      var u = ratings(i).user
    +      var p = ratings(i).product
    +      var r = ratings(i).rating
    +      u = u - 25
    +      p = p - 25
    +      ratings(i) = new Rating(u,p,r)
    +    }
    +    val ratingsRDD = sc.parallelize(ratings)
    +
    +    val model = ALS.train(ratingsRDD, 5, 15)
    +
    +    var pairs = new Array[(Int, Int)](0)
    +    for (u <- -25 until 25; p <- -25 until 25) {
    +      pairs = pairs :+ (u, p)
    +    }
    +    val ans = model.predict(sc.parallelize(pairs)).collect
    +    for (r <- ans) {
    +      val u = r.user + 25
    +      val p = r.product + 25
    +      val v = r.rating
    +      val error = v - correct.get(u,p)
    --- End diff --
    
    Put a space after `,`


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

Mime
View raw message