关联规则挖掘问题的形式描述
给定事务的集合, 关联规则发现是指找出支持度大于等于minsup并且置信度大于等于minconf的所有规则, 其中minsup和minconf是对应的支持度和置信度的阈值.
1584字约5分钟
大数据算法关联分析
2024-04-30
我们首先来看一下四种数据挖掘任务里面的关联分析. 在关联分析中需要处理两个关键的问题:
我们将先介绍关联分析中所需要用到的一些基础知识, 然后介绍Apriori算法, 最后在剩下的部分重点讨论上面提到的这两个问题.
TID | 面包 | 牛奶 | 尿布 | 啤酒 | 鸡蛋 | 可乐 |
---|---|---|---|---|---|---|
1 | 1 | 1 | 1 | 0 | 0 | 0 |
2 | 0 | 1 | 0 | 1 | 0 | 0 |
3 | 0 | 0 | 1 | 1 | 1 | 1 |
4 | 0 | 1 | 1 | 1 | 0 | 0 |
表1.1
表中的列我们称之为: 项
, 包含零个或多个项的集合称为项集
. 如果一个项集包含k个项, 则称之为k-项集
.
例如: {啤酒, 尿布, 牛奶} 是一个3-项集.
项集我们用 I={i1,i2,…,id} 来表示.
表中的行我们称之为: 事务
, 用 T={t1,t2,…,tN} 表示, 第i行即为ti. 每个事务ti包含的项集都是I的子集.
对于项集X, 数学上定义其支持度σ(X)表示为:
σ(X)=∣{ti∣X⊆ti,ti∈T}∣(1.1)
用人话来讲就是某一个项集在所有事务中出现的个数. 例如在表1.1中, 项集{面包, 牛奶}$的支持度为1, 因为该项集只在第一行(即 t1)中出现了一次. 而项集{尿布, 啤酒}的支持度为2.
我们定义:
s(X)=Nσ(X)(1.2)
如果s(X)的值比用户设置的某些阈值minsup大, 则称项集X时频繁的.
可以看到, 对于项集X来说, 在固定的事务数量N的情况下, 其支持度越高, 我们认为其越频繁.
关联规则是形如X→Y 的蕴含表达式, 其中X和Y是不相交的项集.
关联规则通常是我们关联分析所得到的结果, 那么我们如何判断该结论是否是我们想要的, 或者说这个规则是否足够"好"呢? 通常我们使用两个度量来衡量规则的强度: 支持度
和置信度
. 其中支持度确定规则可以用于给定数据集的频繁程度, 而置信度确定Y在包含X的事务中出现的频繁程度. 支持度(s)和置信度(c)的定义如下:
s(X→Y)=Nσ(X∪Y)(1.3)
c(X→Y)=σ(X)σ(X∪Y)(1.4)
以表1.1为例: 考虑规则{牛奶, 尿布} → {啤酒}. 显然, X∪Y = {牛奶, 尿布, 啤酒}, 对于该项集计算其支持度 σ ({牛奶, 尿布, 啤酒})=1, 而事务总数为4, 所以规则的支持度为 41=0.25. 而 X= {牛奶, 尿布} 的支持度为σ(X)=2. 易得该规则的置信度为21=0.5.
注意
由关联规则做出的推论并不必然蕴含因果关系. 只是说, 它有时候能表示规则前件和后件中的项同时出现的概率很大, 具有统计相关性.
如果想要确定因果关系, 则必须知道数据中哪些属性是导致结果发生的原因, 并且通常涉及随时间推移发生的联系.
关联规则挖掘问题的形式描述
给定事务的集合T, 关联规则发现是指找出支持度大于等于minsup并且置信度大于等于minconf的所有规则, 其中minsup和minconf是对应的支持度和置信度的阈值.
现在我们根据这个定义很容易得出, 挖掘关联规则的一种暴力方法就是: 计算每个可能的规则的支持度和置信度. 但是这个方法的计算代价往往高得令人望而却步, 因为通常数据集中可以提取出的规则的数据可达指数级. 更具体地说, 假设规则的左边和右边都不是空集, 那么从包含d个项的数据集提取的可能规则的总数R=3d−2d+1+1. 所以在计算的过程中事先对规则进行剪枝而不必计算它们的支持度和置信度将是非常重要的.
提高关联规则挖掘算法性能的第一步就是拆分支持度和置信度的要求. 我们由前面的公式(1.3)、公式(1.4)可以看出规则X→Y的支持度和其对应项集X∪Y是相同的. 所以如果项集X∪Y是非频繁的, 那么则可以立刻剪枝剪掉对应的候选规则X→Y, 并且不必计算器置信度值了. 例如: 对于项集{啤酒, 尿布, 牛奶}来说, 如果其是非频繁的, 则不必计算对应的6个规则:
因此, 大多数关联规则挖掘算法通常采用的一种策略是将挖掘任务分解成两个主要的子任务:
一般来说, 频繁项集的产生的计算开销是远大于规则生成的计算开销的.
在接下来的章节里面, 我们将讨论频繁项集的产生以及先验理论.