Github user BryanCutler commented on a diff in the pull request:
https://github.com/apache/spark/pull/12896#discussion_r62096512
--- Diff:
mllib/src/test/scala/org/apache/spark/ml/recommendation/ALSSuite.scala ---
@@ -486,6 +486,39 @@ class ALSSuite
assert(getFactors(model.userFactors) ===
getFactors(model2.userFactors))
assert(getFactors(model.itemFactors) ===
getFactors(model2.itemFactors))
}
+
+ test("ALS unknown user/item prediction strategy") {
+ val sqlContext = this.sqlContext
+ import sqlContext.implicits._
+ import org.apache.spark.sql.functions._
+
+ val (ratings, _) = genExplicitTestData(numUsers = 4, numItems = 4,
rank = 1)
+ val data = ratings.toDF
+ val knownUser = data.select(max("user")).as[Int].first()
+ val unknownUser = knownUser + 10
+ val knownItem = data.select(max("item")).as[Int].first()
+ val unknownItem = knownItem + 20
+ val test = Seq(
+ (unknownUser, unknownItem),
+ (knownUser, unknownItem),
+ (unknownUser, knownItem),
+ (knownUser, knownItem)
+ ).toDF("user", "item")
+
+ val als = new ALS().setMaxIter(1).setRank(1)
+ // default is 'nan'
+ val defaultModel = als.fit(data)
+ val defaultPredictions =
defaultModel.transform(test).select("prediction").as[Float].collect()
+ assert(defaultPredictions.length == 4)
+ defaultPredictions.slice(0, 3).foreach(p => assert(p.isNaN))
--- End diff --
no big deal, but slightly cleaner
```scala
defaultPredictions.slice(0, 3).foreach(_.isNaN)
```
---
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 [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]