a7b7a194ac
There is a mistake in the URLs of the Scala section of FP-Growth in the MLlib Frequent Pattern Mining documentation. The URL points to https://spark.apache.org/docs/latest/api/java/org/apache/spark/mllib/fpm/FPGrowth.html which is the Java's API, the link should point to the Scala API https://spark.apache.org/docs/latest/api/scala/index.html#org.apache.spark.mllib.fpm.FPGrowth
There's another mistake in the FP-GrowthModel in the same section, the link points, again, to the Java's API https://spark.apache.org/docs/latest/api/java/org/apache/spark/mllib/fpm/FPGrowthModel.html, the link should point to the Scala API https://spark.apache.org/docs/latest/api/scala/index.html#org.apache.spark.mllib.fpm.FPGrowthModel
Author: FavioVazquez <favio.vazquezp@gmail.com>
Closes #6722 from FavioVazquez/fix-wrog-urls-mllib-fpgrowth and squashes the following commits:
e1ca54d [FavioVazquez] - Fixed wrong URLs in MLlib Frequent Pattern Mining, FP-Growth Scala section
ad882a3 [FavioVazquez] Merge remote-tracking branch 'upstream/master'
f27a20b [FavioVazquez] Merge remote-tracking branch 'upstream/master'
9af7074 [FavioVazquez] Merge remote-tracking branch 'upstream/master'
edab1ef [FavioVazquez] Merge remote-tracking branch 'upstream/master'
b2e2f8c [FavioVazquez] Merge remote-tracking branch 'upstream/master'
(cherry picked from commit 490d5a72ec
)
Signed-off-by: Sean Owen <sowen@cloudera.com>
99 lines
3.8 KiB
Markdown
99 lines
3.8 KiB
Markdown
---
|
|
layout: global
|
|
title: Frequent Pattern Mining - MLlib
|
|
displayTitle: <a href="mllib-guide.html">MLlib</a> - Frequent Pattern Mining
|
|
---
|
|
|
|
Mining frequent items, itemsets, subsequences, or other substructures is usually among the
|
|
first steps to analyze a large-scale dataset, which has been an active research topic in
|
|
data mining for years.
|
|
We refer users to Wikipedia's [association rule learning](http://en.wikipedia.org/wiki/Association_rule_learning)
|
|
for more information.
|
|
MLlib provides a parallel implementation of FP-growth,
|
|
a popular algorithm to mining frequent itemsets.
|
|
|
|
## FP-growth
|
|
|
|
The FP-growth algorithm is described in the paper
|
|
[Han et al., Mining frequent patterns without candidate generation](http://dx.doi.org/10.1145/335191.335372),
|
|
where "FP" stands for frequent pattern.
|
|
Given a dataset of transactions, the first step of FP-growth is to calculate item frequencies and identify frequent items.
|
|
Different from [Apriori-like](http://en.wikipedia.org/wiki/Apriori_algorithm) algorithms designed for the same purpose,
|
|
the second step of FP-growth uses a suffix tree (FP-tree) structure to encode transactions without generating candidate sets
|
|
explicitly, which are usually expensive to generate.
|
|
After the second step, the frequent itemsets can be extracted from the FP-tree.
|
|
In MLlib, we implemented a parallel version of FP-growth called PFP,
|
|
as described in [Li et al., PFP: Parallel FP-growth for query recommendation](http://dx.doi.org/10.1145/1454008.1454027).
|
|
PFP distributes the work of growing FP-trees based on the suffices of transactions,
|
|
and hence more scalable than a single-machine implementation.
|
|
We refer users to the papers for more details.
|
|
|
|
MLlib's FP-growth implementation takes the following (hyper-)parameters:
|
|
|
|
* `minSupport`: the minimum support for an itemset to be identified as frequent.
|
|
For example, if an item appears 3 out of 5 transactions, it has a support of 3/5=0.6.
|
|
* `numPartitions`: the number of partitions used to distribute the work.
|
|
|
|
**Examples**
|
|
|
|
<div class="codetabs">
|
|
<div data-lang="scala" markdown="1">
|
|
|
|
[`FPGrowth`](api/scala/index.html#org.apache.spark.mllib.fpm.FPGrowth) implements the
|
|
FP-growth algorithm.
|
|
It take a `JavaRDD` of transactions, where each transaction is an `Iterable` of items of a generic type.
|
|
Calling `FPGrowth.run` with transactions returns an
|
|
[`FPGrowthModel`](api/scala/index.html#org.apache.spark.mllib.fpm.FPGrowthModel)
|
|
that stores the frequent itemsets with their frequencies.
|
|
|
|
{% highlight scala %}
|
|
import org.apache.spark.rdd.RDD
|
|
import org.apache.spark.mllib.fpm.{FPGrowth, FPGrowthModel}
|
|
|
|
val transactions: RDD[Array[String]] = ...
|
|
|
|
val fpg = new FPGrowth()
|
|
.setMinSupport(0.2)
|
|
.setNumPartitions(10)
|
|
val model = fpg.run(transactions)
|
|
|
|
model.freqItemsets.collect().foreach { itemset =>
|
|
println(itemset.items.mkString("[", ",", "]") + ", " + itemset.freq)
|
|
}
|
|
{% endhighlight %}
|
|
|
|
</div>
|
|
|
|
<div data-lang="java" markdown="1">
|
|
|
|
[`FPGrowth`](api/java/org/apache/spark/mllib/fpm/FPGrowth.html) implements the
|
|
FP-growth algorithm.
|
|
It take an `RDD` of transactions, where each transaction is an `Array` of items of a generic type.
|
|
Calling `FPGrowth.run` with transactions returns an
|
|
[`FPGrowthModel`](api/java/org/apache/spark/mllib/fpm/FPGrowthModel.html)
|
|
that stores the frequent itemsets with their frequencies.
|
|
|
|
{% highlight java %}
|
|
import java.util.List;
|
|
|
|
import com.google.common.base.Joiner;
|
|
|
|
import org.apache.spark.api.java.JavaRDD;
|
|
import org.apache.spark.mllib.fpm.FPGrowth;
|
|
import org.apache.spark.mllib.fpm.FPGrowthModel;
|
|
|
|
JavaRDD<List<String>> transactions = ...
|
|
|
|
FPGrowth fpg = new FPGrowth()
|
|
.setMinSupport(0.2)
|
|
.setNumPartitions(10);
|
|
FPGrowthModel<String> model = fpg.run(transactions);
|
|
|
|
for (FPGrowth.FreqItemset<String> itemset: model.freqItemsets().toJavaRDD().collect()) {
|
|
System.out.println("[" + Joiner.on(",").join(s.javaItems()) + "], " + s.freq());
|
|
}
|
|
{% endhighlight %}
|
|
|
|
</div>
|
|
</div>
|