在路上

 找回密码
 立即注册
在路上 站点首页 学习 查看内容

Apriori算法实现

2017-2-7 13:39| 发布者: zhangjf| 查看: 606| 评论: 0

摘要: Apriori算法原理:http://blog.csdn.net/kingzone_2008/article/details/8183768 import java.util.HashMap;import java.util.HashSet;import java.util.Iterator;import java.util.Map;import java.util.Set; ...

Apriori算法原理:http://blog.csdn.net/kingzone_2008/article/details/8183768


  1. import java.util.HashMap;
  2. import java.util.HashSet;
  3. import java.util.Iterator;
  4. import java.util.Map;
  5. import java.util.Set;
  6. import java.util.TreeMap;
  7. /**
  8. * <B>关联规则挖掘:Apriori算法</B>
  9. *
  10. * <P>按照Apriori算法的基本思想来实现
  11. *
  12. * @author king
  13. * @since 2013/06/27
  14. *
  15. */
  16. public class Apriori {
  17. private Map<Integer, Set<String>> txDatabase; // 事务数据库
  18. private Float minSup; // 最小支持度
  19. private Float minConf; // 最小置信度
  20. private Integer txDatabaseCount; // 事务数据库中的事务数
  21. private Map<Integer, Set<Set<String>>> freqItemSet; // 频繁项集集合
  22. private Map<Set<String>, Set<Set<String>>> assiciationRules; // 频繁关联规则集合
  23. public Apriori(
  24. Map<Integer, Set<String>> txDatabase,
  25. Float minSup,
  26. Float minConf) {
  27. this.txDatabase = txDatabase;
  28. this.minSup = minSup;
  29. this.minConf = minConf;
  30. this.txDatabaseCount = this.txDatabase.size();
  31. freqItemSet = new TreeMap<Integer, Set<Set<String>>>();
  32. assiciationRules = new HashMap<Set<String>, Set<Set<String>>>();
  33. }
  34. /**
  35. * 扫描事务数据库,计算频繁1-项集
  36. * @return
  37. */
  38. public Map<Set<String>, Float> getFreq1ItemSet() {
  39. Map<Set<String>, Float> freq1ItemSetMap = new HashMap<Set<String>, Float>();
  40. Map<Set<String>, Integer> candFreq1ItemSet = this.getCandFreq1ItemSet();
  41. Iterator<Map.Entry<Set<String>, Integer>> it = candFreq1ItemSet.entrySet().iterator();
  42. while(it.hasNext()) {
  43. Map.Entry<Set<String>, Integer> entry = it.next();
  44. // 计算支持度
  45. Float supported = new Float(entry.getValue().toString())/new Float(txDatabaseCount);
  46. if(supported>=minSup) {
  47. freq1ItemSetMap.put(entry.getKey(), supported);
  48. }
  49. }
  50. return freq1ItemSetMap;
  51. }
  52. /**
  53. * 计算候选频繁1-项集
  54. * @return
  55. */
  56. public Map<Set<String>, Integer> getCandFreq1ItemSet() {
  57. Map<Set<String>, Integer> candFreq1ItemSetMap = new HashMap<Set<String>, Integer>();
  58. Iterator<Map.Entry<Integer, Set<String>>> it = txDatabase.entrySet().iterator();
  59. // 统计支持数,生成候选频繁1-项集
  60. while(it.hasNext()) {
  61. Map.Entry<Integer, Set<String>> entry = it.next();
  62. Set<String> itemSet = entry.getValue();
  63. for(String item : itemSet) {
  64. Set<String> key = new HashSet<String>();
  65. key.add(item.trim());
  66. if(!candFreq1ItemSetMap.containsKey(key)) {
  67. Integer value = 1;
  68. candFreq1ItemSetMap.put(key, value);
  69. }
  70. else {
  71. Integer value = 1+candFreq1ItemSetMap.get(key);
  72. candFreq1ItemSetMap.put(key, value);
  73. }
  74. }
  75. }
  76. return candFreq1ItemSetMap;
  77. }
  78. /**
  79. * 根据频繁(k-1)-项集计算候选频繁k-项集
  80. *
  81. * @param m 其中m=k-1
  82. * @param freqMItemSet 频繁(k-1)-项集
  83. * @return
  84. */
  85. public Set<Set<String>> aprioriGen(int m, Set<Set<String>> freqMItemSet) {
  86. Set<Set<String>> candFreqKItemSet = new HashSet<Set<String>>();
  87. Iterator<Set<String>> it = freqMItemSet.iterator();
  88. Set<String> originalItemSet = null;
  89. while(it.hasNext()) {
  90. originalItemSet = it.next();
  91. Iterator<Set<String>> itr = this.getIterator(originalItemSet, freqMItemSet);
  92. while(itr.hasNext()) {
  93. Set<String> identicalSet = new HashSet<String>(); // 两个项集相同元素的集合(集合的交运算)
  94. identicalSet.addAll(originalItemSet);
  95. Set<String> set = itr.next();
  96. identicalSet.retainAll(set); // identicalSet中剩下的元素是identicalSet与set集合中公有的元素
  97. if(identicalSet.size() == m-1) { // (k-1)-项集中k-2个相同
  98. Set<String> differentSet = new HashSet<String>(); // 两个项集不同元素的集合(集合的差运算)
  99. differentSet.addAll(originalItemSet);
  100. differentSet.removeAll(set); // 因为有k-2个相同,则differentSet中一定剩下一个元素,即differentSet大小为1
  101. differentSet.addAll(set); // 构造候选k-项集的一个元素(set大小为k-1,differentSet大小为k)
  102. if(!this.has_infrequent_subset(differentSet, freqMItemSet))
  103. candFreqKItemSet.add(differentSet); // 加入候选k-项集集合
  104. }
  105. }
  106. }
  107. return candFreqKItemSet;
  108. }
  109. /**
  110. * 使用先验知识,剪枝。若候选k项集中存在k-1项子集不是频繁k-1项集,则删除该候选k项集
  111. * @param candKItemSet
  112. * @param freqMItemSet
  113. * @return
  114. */
  115. private boolean has_infrequent_subset(Set<String> candKItemSet, Set<Set<String>> freqMItemSet) {
  116. Set<String> tempSet = new HashSet<String>();
  117. tempSet.addAll(candKItemSet);
  118. Iterator<String> itItem = candKItemSet.iterator();
  119. while(itItem.hasNext()) {
  120. String item = itItem.next();
  121. tempSet.remove(item);// 该候选去掉一项后变为k-1项集
  122. if(!freqMItemSet.contains(tempSet))// 判断k-1项集是否是频繁项集
  123. return true;
  124. tempSet.add(item);// 恢复
  125. }
  126. return false;
  127. }
  128. /**
  129. * 根据一个频繁k-项集的元素(集合),获取到频繁k-项集的从该元素开始的迭代器实例
  130. * @param itemSet
  131. * @param freqKItemSet 频繁k-项集
  132. * @return
  133. */
  134. private Iterator<Set<String>> getIterator(Set<String> itemSet, Set<Set<String>> freqKItemSet) {
  135. Iterator<Set<String>> it = freqKItemSet.iterator();
  136. while(it.hasNext()) {
  137. if(itemSet.equals(it.next())) {
  138. break;
  139. }
  140. }
  141. return it;
  142. }
  143. /**
  144. * 根据频繁(k-1)-项集,调用aprioriGen方法,计算频繁k-项集
  145. *
  146. * @param k
  147. * @param freqMItemSet 频繁(k-1)-项集
  148. * @return
  149. */
  150. public Map<Set<String>, Float> getFreqKItemSet(int k, Set<Set<String>> freqMItemSet) {
  151. Map<Set<String>, Integer> candFreqKItemSetMap = new HashMap<Set<String>, Integer>();
  152. // 调用aprioriGen方法,得到候选频繁k-项集
  153. Set<Set<String>> candFreqKItemSet = this.aprioriGen(k-1, freqMItemSet);
  154. // 扫描事务数据库
  155. Iterator<Map.Entry<Integer, Set<String>>> it = txDatabase.entrySet().iterator();
  156. // 统计支持数
  157. while(it.hasNext()) {
  158. Map.Entry<Integer, Set<String>> entry = it.next();
  159. Iterator<Set<String>> kit = candFreqKItemSet.iterator();
  160. while(kit.hasNext()) {
  161. Set<String> kSet = kit.next();
  162. Set<String> set = new HashSet<String>();
  163. set.addAll(kSet);
  164. set.removeAll(entry.getValue()); // 候选频繁k-项集与事务数据库中元素做差运算
  165. if(set.isEmpty()) { // 如果拷贝set为空,支持数加1
  166. if(candFreqKItemSetMap.get(kSet) == null) {
  167. Integer value = 1;
  168. candFreqKItemSetMap.put(kSet, value);
  169. }
  170. else {
  171. Integer value = 1+candFreqKItemSetMap.get(kSet);
  172. candFreqKItemSetMap.put(kSet, value);
  173. }
  174. }
  175. }
  176. }
  177. // 计算支持度,生成频繁k-项集,并返回
  178. return support(candFreqKItemSetMap);
  179. }
  180. /**
  181. * 根据候选频繁k-项集,得到频繁k-项集
  182. *
  183. * @param candFreqKItemSetMap 候选k项集(包含支持计数)
  184. * @return freqKItemSetMap 频繁k项集及其支持度(比例)
  185. */
  186. public Map<Set<String>, Float> support(Map<Set<String>, Integer> candFreqKItemSetMap) {
  187. Map<Set<String>, Float> freqKItemSetMap = new HashMap<Set<String>, Float>();
  188. Iterator<Map.Entry<Set<String>, Integer>> it = candFreqKItemSetMap.entrySet().iterator();
  189. while(it.hasNext()) {
  190. Map.Entry<Set<String>, Integer> entry = it.next();
  191. // 计算支持度
  192. Float supportRate = new Float(entry.getValue().toString())/new Float(txDatabaseCount);
  193. if(supportRate<minSup) { // 如果不满足最小支持度,删除
  194. it.remove();
  195. }
  196. else {
  197. freqKItemSetMap.put(entry.getKey(), supportRate);
  198. }
  199. }
  200. return freqKItemSetMap;
  201. }
  202. /**
  203. * 挖掘全部频繁项集
  204. */
  205. public void mineFreqItemSet() {
  206. // 计算频繁1-项集
  207. Set<Set<String>> freqKItemSet = this.getFreq1ItemSet().keySet();
  208. freqItemSet.put(1, freqKItemSet);
  209. // 计算频繁k-项集(k>1)
  210. int k = 2;
  211. while(true) {
  212. Map<Set<String>, Float> freqKItemSetMap = this.getFreqKItemSet(k, freqKItemSet);
  213. if(!freqKItemSetMap.isEmpty()) {
  214. this.freqItemSet.put(k, freqKItemSetMap.keySet());
  215. freqKItemSet = freqKItemSetMap.keySet();
  216. }
  217. else {
  218. break;
  219. }
  220. k++;
  221. }
  222. }
  223. /**
  224. * <P>挖掘频繁关联规则
  225. * <P>首先挖掘出全部的频繁项集,在此基础上挖掘频繁关联规则
  226. */
  227. public void mineAssociationRules() {
  228. freqItemSet.remove(1); // 删除频繁1-项集
  229. Iterator<Map.Entry<Integer, Set<Set<String>>>> it = freqItemSet.entrySet().iterator();
  230. while(it.hasNext()) {
  231. Map.Entry<Integer, Set<Set<String>>> entry = it.next();
  232. for(Set<String> itemSet : entry.getValue()) {
  233. // 对每个频繁项集进行关联规则的挖掘
  234. mine(itemSet);
  235. }
  236. }
  237. }
  238. /**
  239. * 对从频繁项集集合freqItemSet中每迭代出一个频繁项集元素,执行一次关联规则的挖掘
  240. * @param itemSet 频繁项集集合freqItemSet中的一个频繁项集元素
  241. */
  242. public void mine(Set<String> itemSet) {
  243. int n = itemSet.size()/2; // 根据集合的对称性,只需要得到一半的真子集
  244. for(int i=1; i<=n; i++) {
  245. // 得到频繁项集元素itemSet的作为条件的真子集集合
  246. Set<Set<String>> properSubset = ProperSubsetCombination.getProperSubset(i, itemSet);
  247. // 对条件的真子集集合中的每个条件项集,获取到对应的结论项集,从而进一步挖掘频繁关联规则
  248. for(Set<String> conditionSet : properSubset) {
  249. Set<String> conclusionSet = new HashSet<String>();
  250. conclusionSet.addAll(itemSet);
  251. conclusionSet.removeAll(conditionSet); // 删除条件中存在的频繁项
  252. confide(conditionSet, conclusionSet); // 调用计算置信度的方法,并且挖掘出频繁关联规则
  253. }
  254. }
  255. }
  256. /**
  257. * 对得到的一个条件项集和对应的结论项集,计算该关联规则的支持计数,从而根据置信度判断是否是频繁关联规则
  258. * @param conditionSet 条件频繁项集
  259. * @param conclusionSet 结论频繁项集
  260. */
  261. public void confide(Set<String> conditionSet, Set<String> conclusionSet) {
  262. // 扫描事务数据库
  263. Iterator<Map.Entry<Integer, Set<String>>> it = txDatabase.entrySet().iterator();
  264. // 统计关联规则支持计数
  265. int conditionToConclusionCnt = 0; // 关联规则(条件项集推出结论项集)计数
  266. int conclusionToConditionCnt = 0; // 关联规则(结论项集推出条件项集)计数
  267. int supCnt = 0; // 关联规则支持计数
  268. while(it.hasNext()) {
  269. Map.Entry<Integer, Set<String>> entry = it.next();
  270. Set<String> txSet = entry.getValue();
  271. Set<String> set1 = new HashSet<String>();
  272. Set<String> set2 = new HashSet<String>();
  273. set1.addAll(conditionSet);
  274. set1.removeAll(txSet); // 集合差运算:set-txSet
  275. if(set1.isEmpty()) { // 如果set为空,说明事务数据库中包含条件频繁项conditionSet
  276. // 计数
  277. conditionToConclusionCnt++;
  278. }
  279. set2.addAll(conclusionSet);
  280. set2.removeAll(txSet); // 集合差运算:set-txSet
  281. if(set2.isEmpty()) { // 如果set为空,说明事务数据库中包含结论频繁项conclusionSet
  282. // 计数
  283. conclusionToConditionCnt++;
  284. }
  285. if(set1.isEmpty() && set2.isEmpty()) {
  286. supCnt++;
  287. }
  288. }
  289. // 计算置信度
  290. Float conditionToConclusionConf = new Float(supCnt)/new Float(conditionToConclusionCnt);
  291. if(conditionToConclusionConf>=minConf) {
  292. if(assiciationRules.get(conditionSet) == null) { // 如果不存在以该条件频繁项集为条件的关联规则
  293. Set<Set<String>> conclusionSetSet = new HashSet<Set<String>>();
  294. conclusionSetSet.add(conclusionSet);
  295. assiciationRules.put(conditionSet, conclusionSetSet);
  296. }
  297. else {
  298. assiciationRules.get(conditionSet).add(conclusionSet);
  299. }
  300. }
  301. Float conclusionToConditionConf = new Float(supCnt)/new Float(conclusionToConditionCnt);
  302. if(conclusionToConditionConf>=minConf) {
  303. if(assiciationRules.get(conclusionSet) == null) { // 如果不存在以该结论频繁项集为条件的关联规则
  304. Set<Set<String>> conclusionSetSet = new HashSet<Set<String>>();
  305. conclusionSetSet.add(conditionSet);
  306. assiciationRules.put(conclusionSet, conclusionSetSet);
  307. }
  308. else {
  309. assiciationRules.get(conclusionSet).add(conditionSet);
  310. }
  311. }
  312. }
  313. /**
  314. * 经过挖掘得到的频繁项集Map
  315. *
  316. * @return 挖掘得到的频繁项集集合
  317. */
  318. public Map<Integer, Set<Set<String>>> getFreqItemSet() {
  319. return freqItemSet;
  320. }
  321. /**
  322. * 获取挖掘到的全部的频繁关联规则的集合
  323. * @return 频繁关联规则集合
  324. */
  325. public Map<Set<String>, Set<Set<String>>> getAssiciationRules() {
  326. return assiciationRules;
  327. }
  328. }
复制代码

其中ProperSubsetCombination类,是用于生成真子集的辅助类:

  1. import java.util.BitSet;
  2. import java.util.HashSet;
  3. import java.util.Set;
  4. /**
  5. * <B>求频繁项集元素(集合)的非空真子集集合</B>
  6. * <P>从一个集合(大小为n)中取出m(m属于2~n/2的闭区间)个元素的组合实现类,获取非空真子集的集合
  7. *
  8. * @author king
  9. * @date 2013/06/27
  10. *
  11. */
  12. public class ProperSubsetCombination {
  13. private static String[] array;
  14. private static BitSet startBitSet; // 比特集合起始状态
  15. private static BitSet endBitSet; // 比特集合终止状态,用来控制循环
  16. private static Set<Set<String>> properSubset; // 真子集集合
  17. /**
  18. * 计算得到一个集合的非空真子集集合
  19. *
  20. * @param n 真子集的大小
  21. * @param itemSet 一个频繁项集元素
  22. * @return 非空真子集集合
  23. */
  24. public static Set<Set<String>> getProperSubset(int n, Set<String> itemSet) {
  25. String[] array = new String[itemSet.size()];
  26. ProperSubsetCombination.array = itemSet.toArray(array);
  27. properSubset = new HashSet<Set<String>>();
  28. startBitSet = new BitSet();
  29. endBitSet = new BitSet();
  30. // 初始化startBitSet,左侧占满1
  31. for (int i=0; i<n; i++) {
  32. startBitSet.set(i, true);
  33. }
  34. // 初始化endBit,右侧占满1
  35. for (int i=array.length-1; i>=array.length-n; i--) {
  36. endBitSet.set(i, true);
  37. }
  38. // 根据起始startBitSet,将一个组合加入到真子集集合中
  39. get(startBitSet);
  40. while(!startBitSet.equals(endBitSet)) {
  41. int zeroCount = 0; // 统计遇到10后,左边0的个数
  42. int oneCount = 0; // 统计遇到10后,左边1的个数
  43. int pos = 0; // 记录当前遇到10的索引位置
  44. // 遍历startBitSet来确定10出现的位置
  45. for (int i=0; i<array.length; i++) {
  46. if (!startBitSet.get(i)) {
  47. zeroCount++;
  48. }
  49. if (startBitSet.get(i) && !startBitSet.get(i+1)) {
  50. pos = i;
  51. oneCount = i - zeroCount;
  52. // 将10变为01
  53. startBitSet.set(i, false);
  54. startBitSet.set(i+1, true);
  55. break;
  56. }
  57. }
  58. // 将遇到10后,左侧的1全部移动到最左侧
  59. int counter = Math.min(zeroCount, oneCount);
  60. int startIndex = 0;
  61. int endIndex = 0;
  62. if(pos>1 && counter>0) {
  63. pos--;
  64. endIndex = pos;
  65. for (int i=0; i<counter; i++) {
  66. startBitSet.set(startIndex, true);
  67. startBitSet.set(endIndex, false);
  68. startIndex = i+1;
  69. pos--;
  70. if(pos>0) {
  71. endIndex = pos;
  72. }
  73. }
  74. }
  75. get(startBitSet);
  76. }
  77. return properSubset;
  78. }
  79. /**
  80. * 根据一次移位操作得到的startBitSet,得到一个真子集
  81. * @param bitSet
  82. */
  83. private static void get(BitSet bitSet) {
  84. Set<String> set = new HashSet<String>();
  85. for(int i=0; i<array.length; i++) {
  86. if(bitSet.get(i)) {
  87. set.add(array[i]);
  88. }
  89. }
  90. properSubset.add(set);
  91. }
  92. }
复制代码



测试类如下:

  1. import java.io.BufferedReader;
  2. import java.io.File;
  3. import java.io.FileNotFoundException;
  4. import java.io.FileReader;
  5. import java.io.IOException;
  6. import java.util.HashMap;
  7. import java.util.HashSet;
  8. import java.util.Map;
  9. import java.util.Set;
  10. import java.util.TreeSet;
  11. import junit.framework.TestCase;
  12. /**
  13. * <B>Apriori算法测试类</B>
  14. *
  15. * @author king
  16. * @date 2013/07/28
  17. */
  18. public class AprioriTest extends TestCase {
  19. private Apriori apriori;
  20. private Map<Integer, Set<String>> txDatabase;
  21. private Float minSup = new Float("0.50");
  22. private Float minConf = new Float("0.70");
  23. public static void main(String []args) throws Exception {
  24. AprioriTest at = new AprioriTest();
  25. at.setUp();
  26. long from = System.currentTimeMillis();
  27. at.testGetFreqItemSet();
  28. long to = System.currentTimeMillis();
  29. System.out.println("耗时:" + (to-from));
  30. }
  31. @Override
  32. protected void setUp() throws Exception {
  33. // create(); // 构造事务数据库
  34. this.buildData(Integer.MAX_VALUE, "f_faqk_.dat");
  35. apriori = new Apriori(txDatabase, minSup, minConf);
  36. }
  37. /**
  38. * 构造模拟事务数据库txDatabase
  39. */
  40. public void create() {
  41. txDatabase = new HashMap<Integer, Set<String>>();
  42. Set<String> set1 = new TreeSet<String>();
  43. set1.add("A");
  44. set1.add("B");
  45. set1.add("C");
  46. set1.add("E");
  47. txDatabase.put(1, set1);
  48. Set<String> set2 = new TreeSet<String>();
  49. set2.add("A");
  50. set2.add("B");
  51. set2.add("C");
  52. txDatabase.put(2, set2);
  53. Set<String> set3 = new TreeSet<String>();
  54. set3.add("C");
  55. set3.add("D");
  56. txDatabase.put(3, set3);
  57. Set<String> set4 = new TreeSet<String>();
  58. set4.add("A");
  59. set4.add("B");
  60. set4.add("E");
  61. txDatabase.put(4, set4);
  62. }
  63. /**
  64. * 构造数据集
  65. * @param fileName 存储事务数据的文件名
  66. * @param totalcount 获取的事务数
  67. */
  68. public void buildData(int totalCount, String...fileName) {
  69. txDatabase = new HashMap<Integer, Set<String>>();
  70. if(fileName.length !=0){
  71. File file = new File(fileName[0]);
  72. int count = 0;
  73. try {
  74. BufferedReader reader = new BufferedReader(new FileReader(file));
  75. String line;
  76. while( (line = reader.readLine()) != null){
  77. String []arr = line.split(" ");
  78. Set<String> set = new HashSet<String>();
  79. for(String s : arr)
  80. set.add(s);
  81. count++;
  82. this.txDatabase.put(count, set);
  83. if(count >= totalCount) return;
  84. }
  85. } catch (FileNotFoundException e) {
  86. e.printStackTrace();
  87. } catch (IOException e) {
  88. e.printStackTrace();
  89. }
  90. }else{
  91. }
  92. }
  93. /**
  94. * 测试挖掘频繁1-项集
  95. */
  96. public void testFreq1ItemSet() {
  97. System.out.println("挖掘频繁1-项集 : " + apriori.getFreq1ItemSet());
  98. }
  99. /**
  100. * 测试aprioriGen方法,生成候选频繁项集
  101. */
  102. public void testAprioriGen() {
  103. System.out.println(
  104. "候选频繁2-项集 : " +
  105. this.apriori.aprioriGen(1, this.apriori.getFreq1ItemSet().keySet())
  106. );
  107. }
  108. /**
  109. * 测试挖掘频繁2-项集
  110. */
  111. public void testGetFreq2ItemSet() {
  112. System.out.println(
  113. "挖掘频繁2-项集 :" +
  114. this.apriori.getFreqKItemSet(2, this.apriori.getFreq1ItemSet().keySet())
  115. );
  116. }
  117. /**
  118. * 测试挖掘频繁3-项集
  119. */
  120. public void testGetFreq3ItemSet() {
  121. System.out.println(
  122. "挖掘频繁3-项集 :" +
  123. this.apriori.getFreqKItemSet(
  124. 3,
  125. this.apriori.getFreqKItemSet(2, this.apriori.getFreq1ItemSet().keySet()).keySet()
  126. )
  127. );
  128. }
  129. /**
  130. * 测试挖掘全部频繁项集
  131. */
  132. public void testGetFreqItemSet() {
  133. this.apriori.mineFreqItemSet(); // 挖掘频繁项集
  134. System.out.println("挖掘频繁项集 :" + this.apriori.getFreqItemSet());
  135. }
  136. /**
  137. * 测试挖掘全部频繁关联规则
  138. */
  139. public void testMineAssociationRules() {
  140. this.apriori.mineFreqItemSet(); // 挖掘频繁项集
  141. this.apriori.mineAssociationRules();
  142. System.out.println("挖掘频繁关联规则 :" + this.apriori.getAssiciationRules());
  143. }
  144. }
复制代码

参考:http://hi.baidu.com/shirdrn/item/5b74a313d55256711009b5d8

在此基础上添加了has_infrequent_subset方法,此方法使用先验知识进行剪枝,是典型Apriori算法必备的。

来自: http://blog.csdn.net//kingzone_2008/article/details/17127567

最新评论

小黑屋|在路上 ( 蜀ICP备15035742号-1 

;

GMT+8, 2025-7-9 08:31

Copyright 2015-2025 djqfx

返回顶部