Python数据挖掘入门与实践一:计算支持度和置信度

这篇博客介绍了如何使用Python进行数据挖掘,通过计算支持度和置信度来发现购买模式。文章中给出了一个示例代码,该代码读取数据集,遍历购买记录,计算不同商品之间的关联规则,并输出规则的支持度和置信度。
摘要由CSDN通过智能技术生成
 

import numpy as np
from collections import defaultdict


#First,how many rows contain our premise:that a person is buying apples
'''num_apple_purchases=0
for sample in X:
    if sample[3]==1:    #this person bought apples
        num_apple_purchases+=1
print num_apple_purchases'''




def calS(X,n_features):


    #print n_features
    #print X[:5]#every row is a purchase record,evey column is a product
    #five kinds of product
    #bread,milk,cheese,apple and banana
    valid_rules=defaultdict(int)
    invalid_rules=defaultdict(int)
    num_occurances=defaultdict(int)
    print X
    for sample in X:
        for premise in range(5):
            if sample[premise]==0:con
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值