Apriori算法及java实现(8)
发布时间:2021-06-11
发布时间:2021-06-11
Apriori算法详解及java代码实现
Map<String,Double> relationRules=new HashMap<String,Double>();
Set<String> keySet=frequentCollectionMap.keySet();
for (String key : keySet) {
double countAll=frequentCollectionMap.get(key);
String[] keyItems = key.split(ITEM_SPLIT);
if(keyItems.length>1){
List<String> source=new ArrayList<String>();
Collections.addAll(source, keyItems);
List<List<String>> result=new ArrayList<List<String>>();
buildSubSet(source,result);//获得source的所有非空子集
for(List<String> itemList:result){
if(itemList.size()<source.size()){//只处理真子集
List<String> otherList=new ArrayList<String>();
for(String sourceItem:source){
if(!itemList.contains(sourceItem)){
otherList.add(sourceItem);
}
}
String reasonStr="";//前置
String resultStr="";//结果
for(String item:itemList){
reasonStr=reasonStr+item+ITEM_SPLIT;
}
for(String item:otherList){
resultStr=resultStr+item+ITEM_SPLIT;
}
double countReason=frequentCollectionMap.get(reasonStr);
double itemConfidence=countAll/countReason;//计算置信度
if(itemConfidence>=CONFIDENCE){
String rule=reasonStr+CON+resultStr;
relationRules.put(rule, itemConfidence);
}
上一篇:门式起重机装拆安全施工方案
下一篇:安泰公司土地平整施工方案