Skip to content
Snippets Groups Projects
mllib-frequent-pattern-mining.md 7.49 KiB
layout: global
title: Frequent Pattern Mining - spark.mllib
displayTitle: Frequent Pattern Mining - spark.mllib

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 for more information. spark.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, 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 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 spark.mllib, we implemented a parallel version of FP-growth called PFP, as described in Li et al., PFP: Parallel FP-growth for query recommendation. 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.

spark.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

FPGrowth implements the FP-growth algorithm. It take a RDD of transactions, where each transaction is an Array of items of a generic type. Calling FPGrowth.run with transactions returns an FPGrowthModel that stores the frequent itemsets with their frequencies. The following example illustrates how to mine frequent itemsets and association rules (see Association Rules for details) from transactions.

Refer to the FPGrowth Scala docs for details on the API.

{% include_example scala/org/apache/spark/examples/mllib/SimpleFPGrowth.scala %}

FPGrowth implements the FP-growth algorithm. It take an JavaRDD of transactions, where each transaction is an Iterable of items of a generic type. Calling FPGrowth.run with transactions returns an FPGrowthModel that stores the frequent itemsets with their frequencies. The following example illustrates how to mine frequent itemsets and association rules (see Association Rules for details) from transactions.

Refer to the FPGrowth Java docs for details on the API.

{% include_example java/org/apache/spark/examples/mllib/JavaSimpleFPGrowth.java %}

FPGrowth implements the FP-growth algorithm. It take an RDD of transactions, where each transaction is an List of items of a generic type. Calling FPGrowth.train with transactions returns an FPGrowthModel that stores the frequent itemsets with their frequencies.

Refer to the FPGrowth Python docs for more details on the API.

{% include_example python/mllib/fpgrowth_example.py %}

Association Rules

AssociationRules implements a parallel rule generation algorithm for constructing rules that have a single item as the consequent.

Refer to the AssociationRules Scala docs for details on the API.

{% include_example scala/org/apache/spark/examples/mllib/AssociationRulesExample.scala %}

AssociationRules implements a parallel rule generation algorithm for constructing rules that have a single item as the consequent.

Refer to the AssociationRules Java docs for details on the API.

{% include_example java/org/apache/spark/examples/mllib/JavaAssociationRulesExample.java %}