Github user mengxr commented on a diff in the pull request:
https://github.com/apache/spark/pull/7360#discussion_r34605895
--- Diff:
mllib/src/main/scala/org/apache/spark/mllib/fpm/LocalPrefixSpan.scala ---
@@ -76,38 +79,25 @@ private[fpm] object LocalPrefixSpan extends Logging
with Serializable {
}
}
+ def project(database: Iterable[Array[Int]], prefix: Int):
Iterable[Array[Int]] = {
+ database
+ .map(candidateSeq => getSuffix(prefix, candidateSeq))
+ .filter(_.nonEmpty)
+ }
+
/**
* Generates frequent items by filtering the input data using minimal
count level.
- * @param minCount the absolute minimum count
- * @param sequences sequences data
- * @return array of item and count pair
+ * @param minCount the minimum count for an item to be frequent
+ * @param database database of sequences
+ * @return item and count pairs
*/
private def getFreqItemAndCounts(
minCount: Long,
- sequences: Array[Array[Int]]): Array[(Int, Long)] = {
- sequences.flatMap(_.distinct)
- .groupBy(x => x)
- .mapValues(_.length.toLong)
+ database: Iterable[Array[Int]]): Iterable[(Int, Long)] = {
+ database.flatMap(_.distinct)
+ .foldRight(Map[Int, Long]().withDefaultValue(0L)) { case (item, ctr)
=>
+ ctr + (item -> (ctr(item) + 1))
--- End diff --
Use a mutable `Map` and then `ctr(item) += 1` here.
---
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]