Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions mllib/src/main/scala/org/apache/spark/ml/fpm/FPGrowth.scala
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,10 @@ class FPGrowthModel private[ml] (
rule._2.filter(item => !itemset.contains(item))
} else {
Seq.empty
})
}).distinct
} else {
Seq.empty
}.distinct }, dt)
}}, dt)
dataset.withColumn($(predictionCol), predictUDF(col($(featuresCol))))
}

Expand Down
14 changes: 14 additions & 0 deletions mllib/src/test/scala/org/apache/spark/ml/fpm/FPGrowthSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,20 @@ class FPGrowthSuite extends SparkFunSuite with MLlibTestSparkContext with Defaul
FPGrowthSuite.allParamSettings, checkModelData)
}

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("features")
val model = new FPGrowth().fit(dataset)

val prediction = model.transform(
spark.createDataFrame(Seq(Tuple1(Array("1", "2")))).toDF("features")
).first().getAs[Seq[String]]("prediction")

assert(prediction === Seq("3"))
}
}

object FPGrowthSuite {
Expand Down