-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-19791] [ML] Add doc and example for fpgrowth #17130
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
fdce240
ca12877
4223d94
9ce0093
fa4c734
0a5dbb2
de1bfc8
d4828b7
9fef280
9e908d0
16f845c
2f0ef8e
c957ba5
8d0ccb1
e9b090a
99530f1
0fb5a87
170c31e
2b1efb3
45139cd
af0b755
ea3b973
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 |
|---|---|---|
|
|
@@ -35,15 +35,16 @@ We refer users to the papers for more details. | |
|
|
||
| * `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. | ||
| * `minConfidence`: minimum confidence for generating Association Rule. The parameter has no effect during `fit`, but specify | ||
| the minimum confidence for generating association rules from frequent itemsets. | ||
| * `numPartitions`: the number of partitions used to distribute the work. | ||
| * `minConfidence`: minimum confidence for generating Association Rule. The parameter will not affect the mining | ||
| for frequent itemsets,, but specify the minimum confidence for generating association rules from frequent itemsets. | ||
| * `numPartitions`: the number of partitions used to distribute the work. By default the param is not set, and | ||
| partition number of the input dataset is used. | ||
|
||
|
|
||
| The `FPGrowthModel` provides: | ||
|
|
||
| * `freqItemsets`: frequent itemsets in the format of DataFrame("items"[Seq], "freq"[Long]) | ||
| * `freqItemsets`: frequent itemsets in the format of DataFrame("items"[Array], "freq"[Long]) | ||
| * `associationRules`: association rules generated with confidence above `minConfidence`, in the format of | ||
| DataFrame("antecedent"[Seq], "consequent"[Seq], "confidence"[Double]). | ||
| DataFrame("antecedent"[Array], "consequent"[Array], "confidence"[Double]). | ||
| * `transform`: The transform method examines the input items against all the association rules and | ||
| summarize the consequents as prediction. The prediction column has the same data type as the | ||
|
||
| input column and does not contain existing items in the input column. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,7 +47,6 @@ object FPGrowthExample { | |
| "1 2") | ||
| ).map(t => t.split(" ")).toDF("features") | ||
|
||
|
|
||
| // Trains a FPGrowth model. | ||
| val fpgrowth = new FPGrowth().setMinSupport(0.5).setMinConfidence(0.6) | ||
| val model = fpgrowth.fit(dataset) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,7 +17,6 @@ | |
|
|
||
| package org.apache.spark.ml.fpm | ||
|
|
||
| import scala.collection.mutable.ArrayBuffer | ||
| import scala.reflect.ClassTag | ||
|
|
||
| import org.apache.hadoop.fs.Path | ||
|
|
@@ -41,7 +40,7 @@ private[fpm] trait FPGrowthParams extends Params with HasFeaturesCol with HasPre | |
|
|
||
| /** | ||
| * Minimal support level of the frequent pattern. [0.0, 1.0]. Any pattern that appears | ||
| * more than (minSupport * size-of-the-dataset) times will be output | ||
| * more than (minSupport * size-of-the-dataset) times will be output in the frequent itemsets. | ||
| * Default: 0.3 | ||
| * @group param | ||
| */ | ||
|
|
@@ -69,8 +68,8 @@ private[fpm] trait FPGrowthParams extends Params with HasFeaturesCol with HasPre | |
| def getNumPartitions: Int = $(numPartitions) | ||
|
|
||
| /** | ||
| * Minimal confidence for generating Association Rule. | ||
| * Note that minConfidence has no effect during fitting. | ||
| * Minimal confidence for generating Association Rule. MinConfidence will not affect the mining | ||
|
||
| * for frequent itemsets, but will affect the association rules generation. | ||
| * Default: 0.8 | ||
| * @group param | ||
| */ | ||
|
|
@@ -154,7 +153,6 @@ class FPGrowth @Since("2.2.0") ( | |
| } | ||
| val parentModel = mllibFP.run(items) | ||
| val rows = parentModel.freqItemsets.map(f => Row(f.items, f.freq)) | ||
|
|
||
| val schema = StructType(Seq( | ||
| StructField("items", dataset.schema($(featuresCol)).dataType, nullable = false), | ||
| StructField("freq", LongType, nullable = false))) | ||
|
|
@@ -183,7 +181,7 @@ object FPGrowth extends DefaultParamsReadable[FPGrowth] { | |
| * :: Experimental :: | ||
| * Model fitted by FPGrowth. | ||
| * | ||
| * @param freqItemsets frequent items in the format of DataFrame("items"[Seq], "freq"[Long]) | ||
| * @param freqItemsets frequent itemsets in the format of DataFrame("items"[Array], "freq"[Long]) | ||
| */ | ||
| @Since("2.2.0") | ||
| @Experimental | ||
|
|
@@ -303,13 +301,13 @@ private[fpm] object AssociationRules { | |
|
|
||
| /** | ||
| * Computes the association rules with confidence above minConfidence. | ||
| * @param dataset DataFrame("items", "freq") containing frequent itemset obtained from | ||
| * algorithms like [[FPGrowth]]. | ||
| * @param dataset DataFrame("items"[Array], "freq"[Long]) containing frequent itemsets obtained | ||
| * from algorithms like [[FPGrowth]]. | ||
| * @param itemsCol column name for frequent itemsets | ||
| * @param freqCol column name for frequent itemsets count | ||
| * @param minConfidence minimum confidence for the result association rules | ||
| * @return a DataFrame("antecedent", "consequent", "confidence") containing the association | ||
| * rules. | ||
| * @param freqCol column name for appearance count of the frequent itemsets | ||
| * @param minConfidence minimum confidence for generating the association rules | ||
| * @return a DataFrame("antecedent"[Array], "consequent"[Array], "confidence"[Double]) | ||
| * containing the association rules. | ||
| */ | ||
| def getAssociationRulesFromFP[T: ClassTag]( | ||
| dataset: Dataset[_], | ||
|
|
||
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.
It might be good to give an example for confidence as well since one has been given for support
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.
also, there are two commas after itemsets