apriori如何实现apriori算法
apriori 时间:2021-06-22 阅读:(
)
Clementine关联规则Apriori算法事务模式怎么使用
算法: Apriori算法,使用逐层迭代找出频繁项集。
输入:事务数据库D;最小支持度阈值min_sup。
输出:D 中的频繁项集L。
1) L1 = find_frequent_1_itemsets(D);
2) for (k = 2; Lk-1 ≠ ; k++) {
3) Ck = aproiri_gen(Lk-1,min_sup);
4) for each transaction t D{ //scan D for count
5) Ct = subset(Ck,t); //get subsets of t that are candidates
6) for each candidate c Ct
7) c.count++;
8) }
9) Lk={c Ck | c.count ≥ min_sup}
10) }
11) return L = ∪kLk;问读音:null,Apriori,FP-Growth的读法
汉语标出可真不准确,不方便啊
servlet /s?:vlit/--/se wu li te/
HTML 就是一个一个字母的读,它是hyper text markup language简写
null /n?l/--/na ou/
apriori 英文发音为:/?pri?ri/--/e pe rui ao rui/
FP-Growth 英文发音为:/aif pi: gr?uθ/--/F P-ge rou si/
前面一个词一般读中文 普瑞奥瑞
后面的一个词 直接读英文如何实现apriori算法
import?java.util.HashMap;
import?java.util.HashSet;
import?java.util.Iterator;
import?java.util.Map;
import?java.util.Set;
import?java.util.TreeMap;
/**
*?<B>关联规则挖掘:Apriori算法</B>
*?
*?<P>按照Apriori算法的基本思想来实现
*?
*?@author?king
*?@since?2013/06/27
*?
*/
public?class?Apriori?{
private?Map<Integer,?Set<String>>?txDatabase;?//?事务数据库
private?Float?minSup;?//?最小支持度
private?Float?minConf;?//?最小置信度
private?Integer?txDatabaseCount;?//?事务数据库中的事务数
private?Map<Integer,?Set<Set<String>>>?freqItemSet;?//?频繁项集集合
private?Map<Set<String>,?Set<Set<String>>>?assiciationRules;?//?频繁关联规则集合
public?Apriori(
????Map<Integer,?Set<String>>?txDatabase,?
????Float?minSup,?
????Float?minConf)?{
???this.txDatabase?=?txDatabase;
???this.minSup?=?minSup;
???this.minConf?=?minConf;
???this.txDatabaseCount?=?this.txDatabase.size();
???freqItemSet?=?new?TreeMap<Integer,?Set<Set<String>>>();
???assiciationRules?=?new?HashMap<Set<String>,?Set<Set<String>>>();
}
/**
*?扫描事务数据库,计算频繁1-项集
*?@return
*/
public?Map<Set<String>,?Float>?getFreq1ItemSet()?{
???Map<Set<String>,?Float>?freq1ItemSetMap?=?new?HashMap<Set<String>,?Float>();
???Map<Set<String>,?Integer>?candFreq1ItemSet?=?this.getCandFreq1ItemSet();
???Iterator<Map.Entry<Set<String>,?Integer>>?it?=?candFreq1ItemSet.entrySet().iterator();
???while(it.hasNext())?{
????Map.Entry<Set<String>,?Integer>?entry?=?it.next();
????//?计算支持度
????Float?supported?=?new?Float(entry.getValue().toString())/new?Float(txDatabaseCount);
????if(supported>=minSup)?{
?????freq1ItemSetMap.put(entry.getKey(),?supported);
????}
???}
???return?freq1ItemSetMap;
}
/**
*?计算候选频繁1-项集
*?@return
*/
public?Map<Set<String>,?Integer>?getCandFreq1ItemSet()?{
???Map<Set<String>,?Integer>?candFreq1ItemSetMap?=?new?HashMap<Set<String>,?Integer>();
???Iterator<Map.Entry<Integer,?Set<String>>>?it?=?txDatabase.entrySet().iterator();
???//?统计支持数,生成候选频繁1-项集
???while(it.hasNext())?{
????Map.Entry<Integer,?Set<String>>?entry?=?it.next();
????Set<String>?itemSet?=?entry.getValue();
????for(String?item?:?itemSet)?{
?????Set<String>?key?=?new?HashSet<String>();
?????key.add(item.trim());
?????if(!candFreq1ItemSetMap.containsKey(key))?{
??????Integer?value?=?1;
??????candFreq1ItemSetMap.put(key,?value);
?????}
?????else?{
??????Integer?value?=?1+candFreq1ItemSetMap.get(key);
??????candFreq1ItemSetMap.put(key,?value);
?????}
????}
???}
???return?candFreq1ItemSetMap;
}
/**
*?根据频繁(k-1)-项集计算候选频繁k-项集
*?
*?@param?m?其中m=k-1
*?@param?freqMItemSet?频繁(k-1)-项集
*?@return
*/
public?Set<Set<String>>?aprioriGen(int?m,?Set<Set<String>>?freqMItemSet)?{
???Set<Set<String>>?candFreqKItemSet?=?new?HashSet<Set<String>>();
???Iterator<Set<String>>?it?=?freqMItemSet.iterator();
???Set<String>?originalItemSet?=?null;
???while(it.hasNext())?{
????originalItemSet?=?it.next();
????Iterator<Set<String>>?itr?=?this.getIterator(originalItemSet,?freqMItemSet);
????while(itr.hasNext())?{
?????Set<String>?identicalSet?=?new?HashSet<String>();?//?两个项集相同元素的集合(集合的交运算)????
?????identicalSet.addAll(originalItemSet);?
?????Set<String>?set?=?itr.next();?
?????identicalSet.retainAll(set);?//?identicalSet中剩下的元素是identicalSet与set集合中公有的元素
?????if(identicalSet.size()?==?m-1)?{?//?(k-1)-项集中k-2个相同
??????Set<String>?differentSet?=?new?HashSet<String>();?//?两个项集不同元素的集合(集合的差运算)
??????differentSet.addAll(originalItemSet);
??????differentSet.removeAll(set);?//?因为有k-2个相同,则differentSet中一定剩下一个元素,即differentSet大小为1
??????differentSet.addAll(set);?//?构造候选k-项集的一个元素(set大小为k-1,differentSet大小为k)
??????if(!this.has_infrequent_subset(differentSet,?freqMItemSet))
??????????candFreqKItemSet.add(differentSet);?//?加入候选k-项集集合
?????}
????}
???}
???return?candFreqKItemSet;
}
/**
?*?使用先验知识,剪枝。
若候选k项集中存在k-1项子集不是频繁k-1项集,则删除该候选k项集
?*?@param?candKItemSet
?*?@param?freqMItemSet
?*?@return
?*/
private?boolean?has_infrequent_subset(Set<String>?candKItemSet,?Set<Set<String>>?freqMItemSet)?{
Set<String>?tempSet?=?new?HashSet<String>();
tempSet.addAll(candKItemSet);
Iterator<String>?itItem?=?candKItemSet.iterator();
while(itItem.hasNext())?{
String?item?=?itItem.next();
tempSet.remove(item);//?该候选去掉一项后变为k-1项集
if(!freqMItemSet.contains(tempSet))//?判断k-1项集是否是频繁项集
return?true;
tempSet.add(item);//?恢复
}
return?false;
}
/**
*?根据一个频繁k-项集的元素(集合),获取到频繁k-项集的从该元素开始的迭代器实例
*?@param?itemSet
*?@param?freqKItemSet?频繁k-项集
*?@return
*/
private?Iterator<Set<String>>?getIterator(Set<String>?itemSet,?Set<Set<String>>?freqKItemSet)?{
???Iterator<Set<String>>?it?=?freqKItemSet.iterator();
???while(it.hasNext())?{
????if(itemSet.equals(it.next()))?{
?????break;
????}
???}
???return?it;
}
/**
*?根据频繁(k-1)-项集,调用aprioriGen方法,计算频繁k-项集
*?
*?@param?k?
*?@param?freqMItemSet?频繁(k-1)-项集
*?@return
*/
public?Map<Set<String>,?Float>?getFreqKItemSet(int?k,?Set<Set<String>>?freqMItemSet)?{
???Map<Set<String>,?Integer>?candFreqKItemSetMap?=?new?HashMap<Set<String>,?Integer>();
???//?调用aprioriGen方法,得到候选频繁k-项集
???Set<Set<String>>?candFreqKItemSet?=?this.aprioriGen(k-1,?freqMItemSet);
???//?扫描事务数据库
???Iterator<Map.Entry<Integer,?Set<String>>>?it?=?txDatabase.entrySet().iterator();
???//?统计支持数
???while(it.hasNext())?{
????Map.Entry<Integer,?Set<String>>?entry?=?it.next();
????Iterator<Set<String>>?kit?=?candFreqKItemSet.iterator();
????while(kit.hasNext())?{
?????Set<String>?kSet?=?kit.next();
?????Set<String>?set?=?new?HashSet<String>();
?????set.addAll(kSet);
?????set.removeAll(entry.getValue());?//?候选频繁k-项集与事务数据库中元素做差运算
?????if(set.isEmpty())?{?//?如果拷贝set为空,支持数加1
??????if(candFreqKItemSetMap.get(kSet)?==?null)?{
???????Integer?value?=?1;
???????candFreqKItemSetMap.put(kSet,?value);
??????}
??????else?{
???????Integer?value?=?1+candFreqKItemSetMap.get(kSet);
???????candFreqKItemSetMap.put(kSet,?value);
??????}
?????}
????}
???}
racknerd怎么样?racknerd今天发布了几款美国特价独立服务器的促销,本次商家主推高配置的服务器,各个配置给的都比较高,有Intel和AMD两种,硬盘也有NVMe和SSD等多咱组合可以选择,机房目前有夏洛特、洛杉矶、犹他州可以选择,性价比很高,有需要独服的朋友可以看看。点击进入:racknerd官方网站RackNerd暑假独服促销:CPU:双E5-2680v3 (24核心,48线程)内存...
ihostart怎么样?ihostart是一家国外新商家,主要提供cPanel主机、KVM VPS、大硬盘存储VPS和独立服务器,数据中心位于罗马尼亚,官方明确说明无视DMCA,对版权内容较为宽松。有需要的可以关注一下。目前,iHostART给出了罗马尼亚vps的优惠信息,罗马尼亚VPS无视DMCA、抗投诉vps/2核4G内存/40GB SSD/100M端口月流量2TB,€20/年。点击直达:ih...
hostround怎么样?大硬盘服务器,高防服务器。hostround,美国商家,2017年成立,正规注册公司(Company File #6180543),提供虚拟主机、VPS云主机、美国服务器、荷兰服务器租用等。现在有1款特价大硬盘独服,位于达拉斯,配置还不错,本月订购时包括免费 500Gbps DDoS 保护,有兴趣的可以关注一下。点击直达:hostround官方网站地址美国\荷兰独立服务器...
apriori为你推荐
gps数据格式怎样把GPS测量数据DAT文件转换成EXEL文件?prisma安卓版prisma 安卓版本为什么不能使用素数算法有能写出所有素数的公式吗暴力破解rar怎么暴力破解rar密码?快速且有效的国家法规数据库哪个常用的法律APP比较好用?netbios协议NetBIOS协议起什么作用?音乐代码在html中插入mp3音频的代码是什么za是哪个国家的ci是在哪个国家产生的?哪个国家开始流行的动画分镜头脚本请问什么是动画分镜头脚本,什么是电影分镜头脚本以及什么是广告分镜头脚本?yui3yui 3 月9日 出的专辑的情报
l5520 183是联通还是移动 isp服务商 酷番云 绍兴电信 如何建立邮箱 www789 starry photobucket 腾讯数据库 97rb iptables ddos防火墙 dmz主机 北京自住房申请网站 英国伦敦时间 中国linux操作系统 免费网络推广软件 免费网络电话下载 pressanykeytorestart 更多