Github user hhbyyh commented on a diff in the pull request:
https://github.com/apache/spark/pull/17336#discussion_r109741396
--- Diff: mllib/src/test/scala/org/apache/spark/ml/fpm/FPGrowthSuite.scala
---
@@ -85,38 +85,58 @@ class FPGrowthSuite extends SparkFunSuite with
MLlibTestSparkContext with Defaul
assert(prediction.select("prediction").where("id=3").first().getSeq[String](0).isEmpty)
}
+ test("FPGrowth prediction should not contain duplicates") {
+ // This should generate rule 1 -> 3, 2 -> 3
+ val dataset = spark.createDataFrame(Seq(
+ Array("1", "3"),
+ Array("2", "3")
+ ).map(Tuple1(_))).toDF("items")
+ val model = new FPGrowth().fit(dataset)
+
+ val prediction = model.transform(
+ spark.createDataFrame(Seq(Tuple1(Array("1", "2")))).toDF("items")
+ ).first().getAs[Seq[String]]("prediction")
+
+ assert(prediction === Seq("3"))
+ }
+
+ test("FPGrowthModel setMinConfidence should affect rules generation and
transform") {
+ val model = new
FPGrowth().setMinSupport(0.1).setMinConfidence(0.1).fit(dataset)
+ val oldRulesNum = model.associationRules.count()
+ val oldPredict = model.transform(dataset)
+
+ model.setMinConfidence(0.8765)
+ assert(oldRulesNum > model.associationRules.count())
+
assert(!model.transform(dataset).collect().toSet.equals(oldPredict.collect().toSet))
+
+ // association rules should stay the same for same minConfidence
+ model.setMinConfidence(0.1)
+ assert(oldRulesNum === model.associationRules.count())
+
assert(model.transform(dataset).collect().toSet.equals(oldPredict.collect().toSet))
+ }
+
test("FPGrowth parameter check") {
val fpGrowth = new FPGrowth().setMinSupport(0.4567)
val model = fpGrowth.fit(dataset)
.setMinConfidence(0.5678)
assert(fpGrowth.getMinSupport === 0.4567)
assert(model.getMinConfidence === 0.5678)
+ MLTestingUtils.checkCopy(model)
}
test("read/write") {
def checkModelData(model: FPGrowthModel, model2: FPGrowthModel): Unit
= {
- assert(model.freqItemsets.sort("items").collect() ===
- model2.freqItemsets.sort("items").collect())
+ assert(model.freqItemsets.collect().toSet.equals(
+ model2.freqItemsets.collect().toSet))
+ assert(model.associationRules.collect().toSet.equals(
--- End diff --
Thanks for comment. I added the check since we added some internal cache
fields, I'd like to ensure it does not interfere with the model loading.
---
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]