作家
登录

Apriori算法介绍(Python实现)

作者: 来源: 2017-04-19 08:55:49 阅读 我要评论

in range(1, len_Lksub1): 
  •  l1 = list(list_Lksub1[i]) 
  •  l2 = list(list_Lksub1[j]) 
  •  l1.sort() 
  •  l2.sort() 
  •  if l1[0:k-2] == l2[0:k-2]: 
  •  Ck_item = list_Lksub1[i] | list_Lksub1[j] 
  •  # pruning 
  •  if is_apriori(Ck_item, Lksub1): 
  •  Ck.add(Ck_item) 
  •  return Ck 
  •  
  •  
  • def generate_Lk_by_Ck(data_set, Ck, min_support, support_data): 
  •  ""
  •  Generate Lk by executing a delete policy from Ck. 
  •  Args: 
  •  data_set: A list of transactions. Each transaction contains several items. 
  •  Ck: A set which contains all all frequent candidate k-itemsets. 
  •  min_support: The minimum support. 
  •  support_data: A dictionary. The key is frequent itemset and the value is support. 
  •  Returns
  •  Lk: A set which contains all all frequent k-itemsets. 
  •  ""
  •  Lk = set() 
  •  item_count = {} 
  •  for t in data_set: 
  •  for item in Ck: 
  •  if item.issubset(t): 
  •  if item not in item_count: 
  •  item_count[item] = 1 
  •  else
  •  item_count[item] += 1 
  •  t_num = float(len(data_set)) 
  •  for item in item_count: 
  •  if (item_count[item] / t_num) >= min_support: 
  •  Lk.add(item) 
  •  support_data[item] = item_count[item] / t_num 
  •  return Lk 
  •  
  •  
  • def generate_L(data_set, k, min_support): 
  •  ""
  •  Generate all frequent itemsets. 

      推荐阅读

      家用NAS有什么用?充分挖掘你的NAS功能

    家用NAS有什么竽暌姑?具体整顿如下:1. 存储所有照片并分类整顿。2. 建立本身的视频办事器,出差在外可以播放家里的视频、音频,看照片。3. 存储大年夜量音乐,经由过程光纤声卡直接连到音>>>详细阅读


    本文标题:Apriori算法介绍(Python实现)

    地址:http://www.17bianji.com/lsqh/34841.html

  • 关键词: 探索发现

    乐购科技部分新闻及文章转载自互联网,供读者交流和学习,若有涉及作者版权等问题请及时与我们联系,以便更正、删除或按规定办理。感谢所有提供资讯的网站,欢迎各类媒体与乐购科技进行文章共享合作。

    网友点评
    自媒体专栏

    评论

    热度

    精彩导读
    栏目ID=71的表不存在(操作类型=0)