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);
??????}
?????}
????}
???}
这不端午节和大家一样回家休息几天,也没有照顾网站的更新。今天又出去忙一天没有时间更新,这里简单搜集看看是不是有一些商家促销活动,因为我看到电商平台各种推送活动今天又开始一波,所以说现在的各种促销让人真的很累。比如在前面我们也有看到PacificRack 商家发布过年中活动,这不在端午节(昨天)又发布一款闪购活动,有些朋友姑且较多是端午节活动,刚才有看到活动还在的,如果有需要的朋友可以看看。第一、端...
速云怎么样?速云是一家国人商家。速云商家主要提供广州移动、深圳移动、广州茂名联通、香港HKT等VDS和独立服务器。目前,速云推出深圳独服优惠活动,机房为深圳移动机房,购买深圳服务器可享受5折优惠,目前独立服务器还支持申请免费试用,需要提交工单开通免费体验试用,次月可享受永久8折优惠,也是需工单申请哦!点击进入:速云官方网站地址活动期限至 2021年7月22日速云云服务器优惠活动:活动1:新购首月可...
PIGYun是成立于2019年的国人商家,提供香港、韩国和美西CUVIP-9929等机房线路基于KVM架构的VPS主机,本月商家针对韩国首尔、美国洛杉矶CUVIP-AS29、GIA回程带防御等多条线路VPS提供6-8.5折优惠码,优惠后韩国首尔CN2混合BGP特惠型/美国洛杉矶GIA回程带10Gbps攻击防御VPS主机最低每月14.4元起。下面列出几款不同机房VPS主机配置信息,请留意不同优惠码。...
apriori为你推荐
ata考试什么是ATA银行考试啊中国学生网中国大学生在线邮箱怎么申请?素数算法有能写出所有素数的公式吗ico监管ICO为什么被叫停excel大写金额怎么在excel中设置大写金额怎么用电脑发短信谁知道怎样能用电脑给手机发短信netbios协议NetBIOS协议起什么作用?方正证券官方网方正证券同花顺下载/2010同花顺官方网站/同花顺官方网站首页云办公平台什么叫云办公啊?谁能通俗的给我讲下怎样删除聊天记录自己已发出的微信聊天记录怎样删除才不会让对方看见
成都虚拟空间 中国万网域名注册 长沙域名注册 泛域名绑定 香港bgp机房 联通c套餐 bluevm 韩国电信 美国便宜货网站 lamp配置 hnyd panel1 毫秒英文 微信收钱 怎样建立邮箱 nerds cn3 福建铁通 hkt web服务器安全 更多