Skip to content

Commit 8c478b3

Browse files
author
Jacky Li
committed
fix according to comments
1 parent 3bb74f6 commit 8c478b3

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

examples/src/main/java/org/apache/spark/examples/mllib/JavaFPGrowthExample.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@
3131

3232
/**
3333
* Java example for mining frequent itemsets using FP-growth.
34-
* Example usage: ./bin/run-example org.apache.spark.examples.mllib.JavaFPGrowthExample
35-
* ./data/mllib/sample_fpgrowth.txt
34+
* Example usage: ./bin/run-example mllib.JavaFPGrowthExample ./data/mllib/sample_fpgrowth.txt
3635
*/
3736
public class JavaFPGrowthExample {
3837

@@ -42,7 +41,7 @@ public static void main(String[] args) {
4241
int numPartition = -1;
4342
if (args.length < 1) {
4443
System.err.println(
45-
"Usage: JavaKMeans <input_file> [minSupport] [numPartition]");
44+
"Usage: JavaFPGrowth <input_file> [minSupport] [numPartition]");
4645
System.exit(1);
4746
}
4847
inputFile = args[0];
@@ -58,11 +57,12 @@ public static void main(String[] args) {
5857

5958
JavaRDD<ArrayList<String>> transactions = sc.textFile(inputFile).map(
6059
new Function<String, ArrayList<String>>() {
61-
@Override
62-
public ArrayList<String> call(String s) {
63-
return Lists.newArrayList(s.split(" "));
60+
@Override
61+
public ArrayList<String> call(String s) {
62+
return Lists.newArrayList(s.split(" "));
63+
}
6464
}
65-
});
65+
);
6666

6767
FPGrowthModel<String> model = new FPGrowth()
6868
.setMinSupport(minSupport)

examples/src/main/scala/org/apache/spark/examples/mllib/FPGrowthExample.scala

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@
1717

1818
package org.apache.spark.examples.mllib
1919

20+
import scopt.OptionParser
21+
2022
import org.apache.spark.mllib.fpm.FPGrowth
2123
import org.apache.spark.{SparkConf, SparkContext}
22-
import scopt.OptionParser
2324

2425
/**
2526
* Example for mining frequent itemsets using FP-growth.
26-
* Example usage: ./bin/run-example org.apache.spark.examples.mllib.FPGrowthExample
27-
* --minSupport 0.8 --numPartition 2 ./data/mllib/sample_fpgrowth.txt
27+
* Example usage: ./bin/run-example mllib.FPGrowthExample \
28+
* --minSupport 0.8 --numPartition 2 ./data/mllib/sample_fpgrowth.txt
2829
*/
2930
object FPGrowthExample {
3031

@@ -36,7 +37,7 @@ object FPGrowthExample {
3637
def main(args: Array[String]) {
3738
val defaultParams = Params()
3839

39-
val parser = new OptionParser[Params]("FPGrowth") {
40+
val parser = new OptionParser[Params]("FPGrowthExample") {
4041
head("FPGrowth: an example FP-growth app.")
4142
opt[Double]("minSupport")
4243
.text(s"minimal support level, default: ${defaultParams.minSupport}")
@@ -45,7 +46,8 @@ object FPGrowthExample {
4546
.text(s"number of partition, default: ${defaultParams.numPartition}")
4647
.action((x, c) => c.copy(numPartition = x))
4748
arg[String]("<input>")
48-
.text("input paths to input data set")
49+
.text("input paths to input data set, whose file format is that each line " +
50+
"contains a transaction with each item in String and separated by a space")
4951
.required()
5052
.action((x, c) => c.copy(input = x))
5153
}
@@ -62,14 +64,14 @@ object FPGrowthExample {
6264
val sc = new SparkContext(conf)
6365
val transactions = sc.textFile(params.input).map(_.split(" ")).cache()
6466

65-
println(s"Number of transactions: ${transactions.count}")
67+
println(s"Number of transactions: ${transactions.count()}")
6668

6769
val model = new FPGrowth()
6870
.setMinSupport(params.minSupport)
6971
.setNumPartitions(params.numPartition)
7072
.run(transactions)
7173

72-
println(s"Number of frequent itemsets: ${model.freqItemsets.count}")
74+
println(s"Number of frequent itemsets: ${model.freqItemsets.count()}")
7375

7476
model.freqItemsets.collect().foreach { itemset =>
7577
println(itemset.items.mkString("[", ",", "]") + ", " + itemset.freq)

0 commit comments

Comments
 (0)