[61e40d]: / assoc_rules / AssocFPGrowth.java

Download this file

58 lines (45 with data), 1.5 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package assoc_rules;
import java.io.File;
import java.io.FileWriter;
import java.time.LocalDateTime;
import weka.associations.Apriori;
import weka.associations.FPGrowth;
import weka.core.Instances;
import weka.core.converters.ConverterUtils.DataSource;
/**
* This class implements FP growth algorithm to obtain association rule from clean, UMLS mapped and filtered FAERS data
* @author zhengc
*
*/
public class AssocFPGrowth{
public static void main(String args[]) throws Exception{
//load dataset
String dataset = args[0];
System.out.println("Algorithm starts: " + LocalDateTime.now());
System.out.println();
DataSource source = new DataSource(dataset);
//get instances object
Instances data = source.getDataSet();
int numAttr = data.numAttributes();
int numIns = data.numInstances();
System.out.println("Number of attributes is " + numAttr);
System.out.println("Number of instances is " + numIns);
// lift-based algorithm
String[] opts = new String[10];
opts[0] = "-T"; opts[1] = "1";
opts[2] = "-C"; opts[3] = "1";
opts[4] = "-M"; opts[5] = "0.000002";
opts[6] = "-N"; opts[7] ="200000";
opts[8] = "-I"; opts[9] = "3";
model.setOptions(opts);
//build model
model.buildAssociations(data);
//print out and save the extracted rules to file
String results = model.toString();
System.out.println(results);
FileWriter fw = new FileWriter(new File(resultfile));
fw.write(results);
fw.close();
System.out.println("Algorithm ends: " + LocalDateTime.now());
}
}