Skip to content

Commit fce022a

Browse files
authored
Merge pull request #161 from wangyangting/master
更新 Apriori 文档
2 parents 603ecd8 + cbc8457 commit fce022a

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

docs/11.使用Apriori算法进行关联分析.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,14 @@ Apriori 算法的两个输入参数分别是最小支持度和数据集。
7474

7575
### 生成候选项集
7676

77+
下面会创建一个用于构建初始集合的函数,也会创建一个通过扫描数据集以寻找交易记录子集的函数,
78+
数据扫描的伪代码如下:
79+
* 对数据集中的每条交易记录 tran
80+
* 对每个候选项集 can
81+
* 检查一下 can 是否是 tran 的子集: 如果是则增加 can 的计数值
82+
* 对每个候选项集
83+
* 如果其支持度不低于最小值,则保留该项集
84+
* 返回所有频繁项集列表
7785
以下是一些辅助函数。
7886

7987
#### 加载数据集
@@ -152,6 +160,8 @@ def scanD(D, Ck, minSupport):
152160
return retList, supportData
153161
```
154162

163+
完整代码地址: <https://github.com/apachecn/MachineLearning/blob/master/src/python/11.Apriori/apriori.py>
164+
155165
### 组织完整的 Apriori 算法
156166

157167
#### 输入频繁项集列表 Lk 与返回的元素个数 k,然后输出所有可能的候选项集 Ck
@@ -238,6 +248,8 @@ def apriori(dataSet, minSupport=0.5):
238248

239249
到这一步,我们就找出我们所需要的 `频繁项集` 和他们的 `支持度` 了,接下来再找出关联规则即可!
240250

251+
完整代码地址: <https://github.com/apachecn/MachineLearning/blob/master/src/python/11.Apriori/apriori.py>
252+
241253
## 从频繁项集中挖掘关联规则
242254

243255
前面我们介绍了用于发现 `频繁项集` 的 Apriori 算法,现在要解决的问题是如何找出 `关联规则`

src/python/11.Apriori/apriori.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,8 @@ def testApriori():
310310
print 'L(0.7): ', L1
311311
print 'supportData(0.7): ', supportData1
312312

313+
print '->->->->->->->->->->->->->->->->->->->->->->->->->->->->'
314+
313315
# Apriori 算法生成频繁项集以及它们的支持度
314316
L2, supportData2 = apriori(dataSet, minSupport=0.5)
315317
print 'L(0.5): ', L2
@@ -331,10 +333,10 @@ def testGenerateRules():
331333

332334
def main():
333335
# 测试 Apriori 算法
334-
# testApriori()
336+
testApriori()
335337

336338
# 生成关联规则
337-
testGenerateRules()
339+
# testGenerateRules()
338340

339341
# # 项目案例
340342
# # 构建美国国会投票记录的事务数据集

0 commit comments

Comments
 (0)