Github user feynmanliang commented on a diff in the pull request:

    https://github.com/apache/spark/pull/8207#discussion_r37219309
  
    --- Diff: docs/mllib-frequent-pattern-mining.md ---
    @@ -96,3 +96,76 @@ for (FPGrowth.FreqItemset<String> itemset: 
model.freqItemsets().toJavaRDD().coll
     
     </div>
     </div>
    +
    +## Association Rules
    +
    +Using the `freqItemsets` of an
    
+[`FPGrowthModel`](api/scala/index.html#org.apache.spark.mllib.fpm.FPGrowthModel)
    +generated by
    +[`FPGrowth`](api/scala/index.html#org.apache.spark.mllib.fpm.FPGrowth),
    +[association
    +rules](https://en.wikipedia.org/wiki/Association_rule_learning#Definition)
    +may be constructed.
    
+[AssociationRules](api/scala/index.html#org.apache.spark.mllib.fpm.AssociationRules)
    +implements a parallel rule generation algorithm for constructing rules
    +that have a single item as the consequent.
    +
    +
    +<div class="codetabs">
    +<div data-lang="scala" markdown="1">
    +{% highlight scala %}
    +import org.apache.spark.rdd.RDD
    +import org.apache.spark.mllib.fpm.AssociationRules
    +import org.apache.spark.mllib.fpm.FPGrowth.FreqItemset
    +
    +val freqItemsets = sc.parallelize(Seq(
    +  new FreqItemset(Array("a"), 15L),
    +  new FreqItemset(Array("b"), 35L),
    +  new FreqItemset(Array("a", "b"), 12L)
    +));
    +
    +val ar = new AssociationRules()
    +  .setMinConfidence(0.8)
    +val results = ar.run(freqItemsets)
    +
    +results.collect().foreach { rule =>
    +  println("[" + rule.antecedent.mkString(",")
    +    + "=>"
    +    + rule.consequent.mkString(",") + "]," + rule.confidence)
    +}
    +{% endhighlight %}
    +
    +</div>
    +
    +<div data-lang="java" markdown="1">
    +{% highlight java %}
    +import com.google.common.base.Joiner;
    +import com.google.common.collect.Lists;
    +
    +import org.apache.spark.api.java.JavaRDD;
    +import org.apache.spark.api.java.JavaSparkContext;
    +import org.apache.spark.mllib.fpm.AssociationRules;
    +import org.apache.spark.mllib.fpm.FPGrowth.FreqItemset;
    +
    +JavaRDD<FPGrowth.FreqItemset<String>> freqItemsets = 
sc.parallelize(Lists.newArrayList(
    +  new FreqItemset<String>(new String[] {"a"}, 15L),
    +  new FreqItemset<String>(new String[] {"b"}, 35L),
    +  new FreqItemset<String>(new String[] {"a", "b"}, 12L)
    +));
    +
    +AssociationRules arules = new AssociationRules()
    +  .setMinConfidence(0.8);
    +JavaRDD<AssociationRules.Rule<String>> results = arules.run(freqItemsets);
    +
    +for (AssociationRules.Rule<String> rule: results.collect()) {
    +System.out.println("["
    --- End diff --
    
    OK


---
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]

Reply via email to