Skip to content

Commit 9414d09

Browse files
author
Boyce.Zhang
committed
关联规则频繁项集挖掘增加测试数据
1 parent 8f5ab20 commit 9414d09

File tree

3 files changed

+65
-2
lines changed

3 files changed

+65
-2
lines changed

src/apriori/Itemset.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@ public Itemset frequent_gen(Transactions transactions) {
112112
if (sup >= transactions.minsup()) {
113113
frequentItemset.addItem(item);
114114

115-
System.out.println("> add a item: " + item + ", sup=" + count + "/" + n);
115+
System.out.println("> add a item: " + item + ", sup=" + count + "/" + n + " = " + (double)count/n);
116116
} else {
117-
System.out.println("> remove a item: " + item + ", sup=" + count + "/" + n);
117+
System.out.println("> remove a item: " + item + ", sup=" + count + "/" + n + " = " + (double)count/n);
118118
}
119119
}
120120
System.out.println();

src/apriori/example/Calculator.java

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package apriori.example;
2+
3+
import apriori.Itemset;
4+
import apriori.Transaction;
5+
import apriori.Transactions;
6+
import common.utils.FileUtils;
7+
import common.utils.StringUtils;
8+
9+
import java.io.File;
10+
import java.util.*;
11+
12+
/**
13+
* Created with IntelliJ IDEA.
14+
* User: Boyce
15+
* Date: 7/12/15
16+
* Time: 14:37
17+
* To change this template use File | Settings | File Templates.
18+
*/
19+
public class Calculator {
20+
private final static String BASE_PATH = "/Users/Boyce/GitProjects/Algorithm/src/apriori/example/";
21+
22+
public static void main(String[] args) {
23+
Transactions transactions = new Transactions(0.9, 0.4);
24+
25+
File file = new File(BASE_PATH + "data/accidents.dat");
26+
List<String> lines = FileUtils.readLines(file);
27+
28+
Transaction t;
29+
for (int i=0;i<lines.size(); i++) {
30+
String line = lines.get(i);
31+
if (StringUtils.isNotEmpty(line)) {
32+
t = new Transaction("t" + i, transactions);
33+
34+
String[] items = line.split(" ");
35+
int length = items.length;
36+
37+
for (int j=0; j<length; j++) {
38+
t.addItem(items[j]);
39+
}
40+
}
41+
}
42+
43+
System.out.println(transactions);
44+
System.out.println(transactions.n());
45+
46+
// for
47+
Itemset c = Itemset.init(transactions);
48+
System.out.println(c);
49+
50+
Itemset f = c.frequent_gen(transactions);
51+
System.out.println(f);
52+
53+
while (!c.isEmpty()) {
54+
c = f.candidate_gen();
55+
System.out.println("candidate set: " + c);
56+
57+
if (!c.isEmpty()) {
58+
f = c.frequent_gen(transactions);
59+
System.out.println("frequent set: " + f);
60+
}
61+
}
62+
}
63+
}

src/apriori/example/data/data.zip

27 MB
Binary file not shown.

0 commit comments

Comments
 (0)