diff options
author | Xiangrui Meng <meng@databricks.com> | 2015-02-02 15:55:44 -0800 |
---|---|---|
committer | Xiangrui Meng <meng@databricks.com> | 2015-02-02 15:55:44 -0800 |
commit | 46d50f151c02c6892fc84a37fdf2a521dc774d1c (patch) | |
tree | 5788c15d5f400f97909ee5bb423d1ba9c20ac153 /mllib/src/test | |
parent | 1646f89d967913ee1f231d9606f8502d13c25804 (diff) | |
download | spark-46d50f151c02c6892fc84a37fdf2a521dc774d1c.tar.gz spark-46d50f151c02c6892fc84a37fdf2a521dc774d1c.tar.bz2 spark-46d50f151c02c6892fc84a37fdf2a521dc774d1c.zip |
[SPARK-5513][MLLIB] Add nonnegative option to ml's ALS
This PR ports the NNLS solver to the new ALS implementation.
CC: coderxiang
Author: Xiangrui Meng <meng@databricks.com>
Closes #4302 from mengxr/SPARK-5513 and squashes the following commits:
4cbdab0 [Xiangrui Meng] fix serialization
88de634 [Xiangrui Meng] add NNLS to ml's ALS
Diffstat (limited to 'mllib/src/test')
-rw-r--r-- | mllib/src/test/scala/org/apache/spark/ml/recommendation/ALSSuite.scala | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/mllib/src/test/scala/org/apache/spark/ml/recommendation/ALSSuite.scala b/mllib/src/test/scala/org/apache/spark/ml/recommendation/ALSSuite.scala index 07aff56fb7..ee08c3c327 100644 --- a/mllib/src/test/scala/org/apache/spark/ml/recommendation/ALSSuite.scala +++ b/mllib/src/test/scala/org/apache/spark/ml/recommendation/ALSSuite.scala @@ -444,4 +444,15 @@ class ALSSuite extends FunSuite with MLlibTestSparkContext with Logging { val (strUserFactors, _) = ALS.train(strRatings, rank = 2, maxIter = 4) assert(strUserFactors.first()._1.getClass === classOf[String]) } + + test("nonnegative constraint") { + val (ratings, _) = genImplicitTestData(numUsers = 20, numItems = 40, rank = 2, noiseStd = 0.01) + val (userFactors, itemFactors) = ALS.train(ratings, rank = 2, maxIter = 4, nonnegative = true) + def isNonnegative(factors: RDD[(Int, Array[Float])]): Boolean = { + factors.values.map { _.forall(_ >= 0.0) }.reduce(_ && _) + } + assert(isNonnegative(userFactors)) + assert(isNonnegative(itemFactors)) + // TODO: Validate the solution. + } } |