|
|
|
@ -41,7 +41,7 @@ public class Apriori {
|
|
|
|
|
}
|
|
|
|
|
result.add(rowData);
|
|
|
|
|
}
|
|
|
|
|
System.out.println("\nD:" + result);
|
|
|
|
|
// System.out.println("\nD:" + result);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
// public static ArrayList<ArrayList<String>> readTable(MultipartFile file) {
|
|
|
|
@ -161,10 +161,10 @@ public class Apriori {
|
|
|
|
|
}
|
|
|
|
|
str = C.toString();
|
|
|
|
|
|
|
|
|
|
System.out.println("候选"+t+"项集:C: \n"+C);
|
|
|
|
|
// System.out.println("候选"+t+"项集:C: \n"+C);
|
|
|
|
|
// 二、剪枝步
|
|
|
|
|
pruning(C, L,min_support);
|
|
|
|
|
System.out.println("频繁"+t+"项集:L: \n"+L+"\n");
|
|
|
|
|
// System.out.println("频繁"+t+"项集:L: \n"+L+"\n");
|
|
|
|
|
str = L.toString();
|
|
|
|
|
|
|
|
|
|
//System.out.println("===");
|
|
|
|
@ -219,55 +219,64 @@ public class Apriori {
|
|
|
|
|
List<String> lists=new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
for (ArrayList<String> key : L_ALL.keySet()) {// 对最终的关联集各个事件进行判断
|
|
|
|
|
ArrayList<ArrayList<String>> key_allSubset = getSubset(key);
|
|
|
|
|
//得到所有频繁集中每个集合的子集
|
|
|
|
|
// System.out.println(key_allSubset);
|
|
|
|
|
for (int i = 0; i < key_allSubset.size(); i++) {
|
|
|
|
|
ArrayList<String> item_pre = key_allSubset.get(i);//得到一个真子集
|
|
|
|
|
if (0 < item_pre.size() && item_pre.size() < key.size()) {// 判断是否是非空真子集
|
|
|
|
|
// 各个非空互补真子集之间形成关联事件
|
|
|
|
|
double item_pre_support = L_ALL.get(item_pre);//得到真子集的支持度度
|
|
|
|
|
//System.out.println("itempre="+item_pre_support);
|
|
|
|
|
for (int j = 0; j < key_allSubset.size(); j++) {
|
|
|
|
|
ArrayList<String> item_post = key_allSubset.get(j);
|
|
|
|
|
if (0 < item_post.size()
|
|
|
|
|
&& item_post.size() < key.size()
|
|
|
|
|
&& arrayListUnion(item_pre, item_post).equals(key)
|
|
|
|
|
&& intersectionIsNull(item_pre, item_post))
|
|
|
|
|
//不相交的两个非空真子集,相并为频繁项集
|
|
|
|
|
{
|
|
|
|
|
double d = L_ALL.get(arrayListUnion(item_pre, item_post));
|
|
|
|
|
//double item_post_support = L_ALL.get(item_post);// 互补真子集的支持度比则是事件的置信度
|
|
|
|
|
//System.out.println("item_post="+item_post_support);
|
|
|
|
|
double confident = d
|
|
|
|
|
/ item_pre_support; // 事件的置信度
|
|
|
|
|
if (confident > min_confident) {// 如果事件的置信度大于最小置信度
|
|
|
|
|
//封装对象返回
|
|
|
|
|
if (key != null && !key.isEmpty() && L_ALL != null) {
|
|
|
|
|
ArrayList<ArrayList<String>> key_allSubset = getSubset(key);
|
|
|
|
|
//得到所有频繁集中每个集合的子集
|
|
|
|
|
// System.out.println(key_allSubset);
|
|
|
|
|
for (int i = 0; i < key_allSubset.size(); i++) {
|
|
|
|
|
ArrayList<String> item_pre = key_allSubset.get(i);//得到一个真子集
|
|
|
|
|
if(item_pre.size()>1){
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if(item_pre.isEmpty()){
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (0 < item_pre.size() && item_pre.size() < key.size()) {// 判断是否是非空真子集
|
|
|
|
|
// 各个非空互补真子集之间形成关联事件
|
|
|
|
|
double item_pre_support = L_ALL.get(item_pre);//得到真子集的支持度度
|
|
|
|
|
//System.out.println("itempre="+item_pre_support);
|
|
|
|
|
for (int j = 0; j < key_allSubset.size(); j++) {
|
|
|
|
|
ArrayList<String> item_post = key_allSubset.get(j);
|
|
|
|
|
if (0 < item_post.size()
|
|
|
|
|
&& item_post.size() < key.size()
|
|
|
|
|
&& arrayListUnion(item_pre, item_post).equals(key)
|
|
|
|
|
&& intersectionIsNull(item_pre, item_post))
|
|
|
|
|
//不相交的两个非空真子集,相并为频繁项集
|
|
|
|
|
{
|
|
|
|
|
double d = L_ALL.get(arrayListUnion(item_pre, item_post));
|
|
|
|
|
//double item_post_support = L_ALL.get(item_post);// 互补真子集的支持度比则是事件的置信度
|
|
|
|
|
//System.out.println("item_post="+item_post_support);
|
|
|
|
|
double confident = d
|
|
|
|
|
/ item_pre_support; // 事件的置信度
|
|
|
|
|
if (confident > min_confident) {// 如果事件的置信度大于最小置信度
|
|
|
|
|
//封装对象返回
|
|
|
|
|
|
|
|
|
|
AssociationRulesDTO associationRulesDTO=new AssociationRulesDTO();
|
|
|
|
|
associationRulesDTO.setCorrelation(item_pre);
|
|
|
|
|
associationRulesDTO.setAssociated(item_post);
|
|
|
|
|
associationRulesDTO.setConfidenceLevel(confident);
|
|
|
|
|
AssociationRulesDTO associationRulesDTO=new AssociationRulesDTO();
|
|
|
|
|
associationRulesDTO.setCorrelation(item_pre);
|
|
|
|
|
associationRulesDTO.setAssociated(item_post);
|
|
|
|
|
associationRulesDTO.setConfidenceLevel(confident);
|
|
|
|
|
|
|
|
|
|
String string=item_pre + "==>" + item_post+"==>" + confident;
|
|
|
|
|
associationRulesDTO.setRule(string);
|
|
|
|
|
String string=item_pre + "==>" + item_post+"==>" + confident;
|
|
|
|
|
associationRulesDTO.setRule(string);
|
|
|
|
|
|
|
|
|
|
list.add(associationRulesDTO);
|
|
|
|
|
list.add(associationRulesDTO);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
System.out.print(item_pre + "==>" + item_post );// 则是一个关联事件
|
|
|
|
|
System.out.println("==>" + confident);
|
|
|
|
|
// System.out.print(item_pre + "==>" + item_post );// 则是一个关联事件
|
|
|
|
|
// System.out.println("==>" + confident);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lists.add(string);
|
|
|
|
|
lists.add(string);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|