-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-9898][MLlib] Prefix Span user guide #8253
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -96,3 +96,91 @@ for (FPGrowth.FreqItemset<String> itemset: model.freqItemsets().toJavaRDD().coll | |
|
|
||
| </div> | ||
| </div> | ||
|
|
||
| ## Prefix Span | ||
|
|
||
| Prefix Span is a sequential pattern mining algorithm described in | ||
| [Mortazavi-Asl et al., Mining Sequential Patterns by Pattern-Growth: The | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK |
||
| PrefixSpan Approach](http://dx.doi.org/10.1109%2FTKDE.2004.77). We refer | ||
| the reader to the referenced paper for formalizing the sequential | ||
| pattern mining problem. | ||
|
|
||
| MLlib's FP-growth implementation takes the following parameters: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK |
||
|
|
||
| * `minSupport`: the minimum support required to be considered a frequent | ||
| sequential pattern. | ||
| * `maxPatternLength`: the maximum length of a frequent sequential | ||
| pattern. Any frequent pattern exceeding this length will not be | ||
| included in the results. | ||
| * `maxLocalProjDBSize`: the maximum number of items allowed in a | ||
| prefix-projected database before local iterative processing of the | ||
| projected databse begins. This parameter should be tuned with respect | ||
| to the size of your executors. | ||
|
|
||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove extra empty lines.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK |
||
|
|
||
| **Examples** | ||
|
|
||
| <div class="codetabs"> | ||
| <div data-lang="scala" markdown="1"> | ||
|
|
||
| [`PrefixSpan`](api/scala/index.html#org.apache.spark.mllib.fpm.PrefixSpan) implements the | ||
| Prefix Span algorithm. | ||
| Calling `PrefixSpan.run` returns a | ||
| [`PrefixSpanModel`](api/scala/index.html#org.apache.spark.mllib.fpm.PrefixSpan) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK |
||
| that stores the frequent sequences with their frequencies. | ||
|
|
||
| {% highlight scala %} | ||
| import org.apache.spark.mllib.fpm.PrefixSpan | ||
|
|
||
| val sequences = Seq( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a comment and list the items using the notation from the paper.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be mentioned outside the code tabs, because it applies to all examples.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK |
||
| Array(Array(1, 2), Array(3)), | ||
| Array(Array(1), Array(3, 2), Array(1, 2)), | ||
| Array(Array(1, 2), Array(5)), | ||
| Array(Array(6))) | ||
| val rdd = sc.parallelize(sequences, 2).cache() | ||
|
|
||
| val prefixSpan = new PrefixSpan() | ||
| .setMinSupport(0.5) | ||
| .setMaxPatternLength(5) | ||
| val model = prefixSpan.run(rdd) | ||
| model.freqSequences.collect().foreach { freqSequence => | ||
| println(freqSequence.sequence.map(_.mkString("(", ",", ")")).mkString("[",",","]") + ", " + freqSequence.freq) | ||
| } | ||
| {% endhighlight %} | ||
|
|
||
| </div> | ||
|
|
||
| <div data-lang="java" markdown="1"> | ||
|
|
||
| [`PrefixSpan`](api/java/org/apache/spark/mllib/fpm/PrefixSpan.html) implements the | ||
| Prefix Span algorithm. | ||
| Calling `PrefixSpan.run` returns a | ||
| [`PrefixSpanModel`](api/java/org/apache/spark/mllib/fpm/PrefixSpanModel.html) | ||
| that stores the frequent sequences with their frequencies. | ||
|
|
||
| {% highlight java %} | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
|
|
||
| import org.apache.spark.mllib.fpm.PrefixSpan; | ||
| import org.apache.spark.mllib.fpm.PrefixSpanModel; | ||
|
|
||
| JavaRDD<List<List<Integer>>> sequences = sc.parallelize(Arrays.asList( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Create the local list first, to be consistent with the Scala example.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, I modified Scala example to directly create RDD as well
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. either approach is fine:) |
||
| Arrays.asList(Arrays.asList(1, 2), Arrays.asList(3)), | ||
| Arrays.asList(Arrays.asList(1), Arrays.asList(3, 2), Arrays.asList(1, 2)), | ||
| Arrays.asList(Arrays.asList(1, 2), Arrays.asList(5)), | ||
| Arrays.asList(Arrays.asList(6)) | ||
| ), 2); | ||
| PrefixSpan prefixSpan = new PrefixSpan() | ||
| .setMinSupport(0.5) | ||
| .setMaxPatternLength(5); | ||
| PrefixSpanModel<Integer> model = prefixSpan.run(sequences); | ||
| for (PrefixSpan.FreqSequence<Integer> freqSeq: model.freqSequences().toJavaRDD().collect()) { | ||
| System.out.println(freqSeq.javaSequence() + ", " + freqSeq.freq()); | ||
| } | ||
| {% endhighlight %} | ||
|
|
||
| </div> | ||
| </div> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefix Span->PrefixSpan(please also fix this in other places)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK